summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Qiu <zqiu@google.com>2016-09-20 12:36:31 -0700
committerPeter Qiu <zqiu@google.com>2016-11-04 23:29:40 +0000
commit81080a8430568399a14e9b85007a8aaea5c2e6eb (patch)
treec08a64b9b6eb8dbb27471ccd7bcb7a61da821094
parenta8a5644b48660a166adfad9fdc274cbdb44cdf4b (diff)
downloadandroid_frameworks_opt_net_wifi-81080a8430568399a14e9b85007a8aaea5c2e6eb.tar.gz
android_frameworks_opt_net_wifi-81080a8430568399a14e9b85007a8aaea5c2e6eb.tar.bz2
android_frameworks_opt_net_wifi-81080a8430568399a14e9b85007a8aaea5c2e6eb.zip
DO NOT MERGE: OMAParser: throw IOException when parsing a null XML string
This avoids a NullPointerException when parsing a null XML string. OMAParser.parse is only used by PasspointManagementObjectManager for adding/building/modifying a HomeSP from a XML string. It is fine to use IOException since it is already being handled gracefully by its upstream callers. Bug: 31497435 Test: unit tests Test: Verify system server crashes when executing the command below without the fix and doesn't crash with the fix: "adb shell service call wifi 8 i32 0" Change-Id: If2ad13b8573d49ba0ccbea2427f3c63d841f866d (cherry picked from commit 519056861a467ae64e142ff07d53891514ef9c70)
-rw-r--r--service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java36
2 files changed, 39 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java
index cbcd81d16..d39fa33a1 100644
--- a/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java
+++ b/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java
@@ -26,6 +26,9 @@ public class OMAParser extends DefaultHandler {
}
public MOTree parse(String text, String urn) throws IOException, SAXException {
+ if (text == null) {
+ throw new IOException("Missing text string");
+ }
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(new InputSource(new StringReader(text)), this);
diff --git a/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java b/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java
index c76bf91a3..d3022b932 100644
--- a/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java
@@ -193,6 +193,21 @@ public class PasspointManagementObjectManagerTest {
assertEquals("testIdentity1", homeSP.getCredential().getUserName());
}
+ /** Verify IOException is thrown when trying to add a SP from a null XML string. */
+ @Test(expected = IOException.class)
+ public void addSPFromNullXmlString() throws Exception {
+ File file = tempFolder.newFile("PerProviderSubscription.conf");
+ PasspointManagementObjectManager moMgr = new PasspointManagementObjectManager(file, true);
+ String xml = null; // Needed to avoid ambiguity on function call.
+ moMgr.addSP(xml);
+ }
+
+ /** Verify IOException is thrown when trying to build a SP from a null XML string. */
+ @Test(expected = IOException.class)
+ public void buildSPFromNullXmlString() throws Exception {
+ PasspointManagementObjectManager.buildSP(null);
+ }
+
/** verify that xml serialization/deserialization works */
public void checkXml() throws Exception {
InputStream in = getClass().getClassLoader().getResourceAsStream(R2_TTLS_XML_FILE);
@@ -268,6 +283,27 @@ public class PasspointManagementObjectManagerTest {
assertEquals(9, homeSP.getUpdateIdentifier());
}
+ /** Verify IOException is thrown when trying to modify a SP using a null XML string. */
+ @Test(expected = IOException.class)
+ public void modifySPFromNullXmlString() throws Exception {
+ File file = createFileFromResource(R2_CONFIG_FILE);
+ PasspointManagementObjectManager moMgr = new PasspointManagementObjectManager(file, true);
+ List<HomeSP> homeSPs = moMgr.loadAllSPs();
+ assertEquals(2, homeSPs.size());
+
+ /* PasspointManagementObjectDefinition with null xmlTree. */
+ String urn = "wfa:mo:hotspot2dot0-perprovidersubscription:1.0";
+ String baseUri = "./Wi-Fi/wi-fi.org/PerProviderSubscription/UpdateIdentifier";
+ String xmlTree = null;
+
+ PasspointManagementObjectDefinition moDef =
+ new PasspointManagementObjectDefinition(baseUri, urn, xmlTree);
+ List<PasspointManagementObjectDefinition> moDefs =
+ new ArrayList<PasspointManagementObjectDefinition>();
+ moDefs.add(moDef);
+ moMgr.modifySP("wi-fi.org", moDefs);
+ }
+
/** verify removing an existing service provider works */
@Test
public void removeSP() throws Exception {