diff options
author | Annie Meng <anniemeng@google.com> | 2018-03-01 11:56:08 +0000 |
---|---|---|
committer | Annie Meng <anniemeng@google.com> | 2018-03-02 11:25:48 +0000 |
commit | 17124f18ecced05652082589a97b89916a8c4dc4 (patch) | |
tree | 34d906a526026cf8bd9458477b2b58c1d221c326 /service | |
parent | 3834a0e07498786c6d66ad07be87fe6b79292b90 (diff) |
Validate restore of old wifi settings
We want to validate that older backups of wifi settings using KEY_WIFI_SUPPLICANT
and KEY_WIFI_CONFIG (which were removed in O) can be restored without
throwing exceptions on invalid backup data. In this case, we
catch potential null cases and number format exceptions that occur when
parsing the network data.
We also add GTS tests to validate that we don't crash when restoring
these malformed backup data sets and that our checks persist.
Bug: 74060048
Test: 1) gts-tradefed run gts -m GtsBackupHostTestCases -t com.google.android.gts.backup.OldWifiSettingsRestoreHostSideTest
2) frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: I44a3c51b11019a0b292eea6e3a8e4ec417aea5fc
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiBackupRestore.java | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiBackupRestore.java b/service/java/com/android/server/wifi/WifiBackupRestore.java index 6b854b114..2d95570fc 100644 --- a/service/java/com/android/server/wifi/WifiBackupRestore.java +++ b/service/java/com/android/server/wifi/WifiBackupRestore.java @@ -654,8 +654,18 @@ public class WifiBackupRestore { Map<String, String> extras = SupplicantStaNetworkHal.parseNetworkExtra( NativeUtil.removeEnclosingQuotes(idString)); + if (extras == null) { + Log.e(TAG, "Error parsing network extras, ignoring network."); + return null; + } String configKey = extras.get( SupplicantStaNetworkHal.ID_STRING_KEY_CONFIG_KEY); + // No ConfigKey was passed but we need it for validating the parsed + // network so we stop the restore. + if (configKey == null) { + Log.e(TAG, "Configuration key was not passed, ignoring network."); + return null; + } if (!configKey.equals(configuration.configKey())) { // ConfigKey mismatches are expected for private networks because the // UID is not preserved across backup/restore. @@ -696,6 +706,13 @@ public class WifiBackupRestore { if (line != null) { if (line.startsWith("network")) { SupplicantNetwork net = SupplicantNetwork.readNetworkFromStream(in); + + // An IOException occurred while trying to read the network. + if (net == null) { + Log.e(TAG, "Error while parsing the network."); + continue; + } + // Networks that use certificates for authentication can't be // restored because the certificates they need don't get restored // (because they are stored in keystore, and can't be restored). @@ -721,10 +738,17 @@ public class WifiBackupRestore { public List<WifiConfiguration> retrieveWifiConfigurations() { ArrayList<WifiConfiguration> wifiConfigurations = new ArrayList<>(); for (SupplicantNetwork net : mNetworks) { - WifiConfiguration wifiConfiguration = net.createWifiConfiguration(); - if (wifiConfiguration != null) { - Log.v(TAG, "Parsed Configuration: " + wifiConfiguration.configKey()); - wifiConfigurations.add(wifiConfiguration); + try { + WifiConfiguration wifiConfiguration = net.createWifiConfiguration(); + if (wifiConfiguration != null) { + Log.v(TAG, "Parsed Configuration: " + wifiConfiguration.configKey()); + wifiConfigurations.add(wifiConfiguration); + } + } catch (NumberFormatException e) { + // Occurs if we are unable to parse the hidden SSID, WEP Key index or + // creator UID. + Log.e(TAG, "Error parsing wifi configuration: " + e); + return null; } } return wifiConfigurations; |