From 08135433b40efd21abab4e929d365b2cc0de1e86 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Thu, 25 Apr 2019 09:15:51 -0700 Subject: NativeUtil: Perform range checks on ssid bytes size NativeUtil.encodeSsid/decodeSsid should perform range checks because the output/input is coming from binder/hwbinder interfaces which assume the ssid is not malformed (i.e within spec mandated size range). Most of the callers of these methods already handle IllegalArgumentException (including the hidden network list built in WifiCondControl). This should fix the reported issue of a hidden SSID added with size > 32 causing crash in wificond. Bug: 130843221 Test: Device boots up & connects to wifi networks. Test: Regression tests. Test: atest com.android.server.wifi Change-Id: I12d8f3b548a65005932bd8bc1c74de37769b0ee8 --- .../android/server/wifi/util/NativeUtilTest.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java index 79dcccfcc..d4bcb479e 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java @@ -127,6 +127,18 @@ public class NativeUtilTest { } } + /** + * Test that conversion of SSID string with len > 32 to bytes fail. + */ + @Test + public void testLargeSsidDecodeFails() throws Exception { + try { + NativeUtil.decodeSsid("\"asdrewqdfgyuiopldsqwertyuiolhdergcv\""); + fail("Expected ssid decode to fail"); + } catch (IllegalArgumentException e) { + } + } + /** * Test that conversion of ssid bytes to hex string ssid works. */ @@ -177,6 +189,25 @@ public class NativeUtilTest { (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a)))); } + /** + * Test that conversion of SSID bytes with len > 32 to string fail. + */ + @Test + public void testLargeSsidEncodeFails() throws Exception { + try { + NativeUtil.encodeSsid(new ArrayList<>( + Arrays.asList((byte) 0xf5, (byte) 0xe4, (byte) 0xab, (byte) 0x78, (byte) 0x78, + (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a, + (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a, + (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a, + (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a, + (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a, + (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a))); + fail("Expected ssid encode to fail"); + } catch (IllegalArgumentException e) { + } + } + /** * Test that parsing of quoted SSID to byte array and vice versa works. */ -- cgit v1.2.3