diff options
author | Etan Cohen <etancohen@google.com> | 2018-10-05 00:04:27 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-10-05 00:04:27 +0000 |
commit | c26d2bfdf8ff6f5049bd599349dbd46e5e053fb4 (patch) | |
tree | b3b1fe10649a7f2e45da5d9efe06ae27eb68dfdd | |
parent | 8d6c5e6b13a710a8df9a81db269e039421d64e0b (diff) | |
parent | 1cb8cdaf63f970533ef80b48ff713ed7c5b120f0 (diff) |
Merge "[RTT] Add NPE checks for invalid MAC addresses from Aware" into pi-dev
-rw-r--r-- | service/java/com/android/server/wifi/rtt/RttServiceImpl.java | 8 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java | 15 |
2 files changed, 17 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/rtt/RttServiceImpl.java b/service/java/com/android/server/wifi/rtt/RttServiceImpl.java index 75e75aa0f..258bdb67f 100644 --- a/service/java/com/android/server/wifi/rtt/RttServiceImpl.java +++ b/service/java/com/android/server/wifi/rtt/RttServiceImpl.java @@ -1016,8 +1016,14 @@ public class RttServiceImpl extends IWifiRttManager.Stub { RangingRequest.Builder newRequestBuilder = new RangingRequest.Builder(); for (ResponderConfig rttPeer : request.request.mRttPeers) { if (rttPeer.peerHandle != null && rttPeer.macAddress == null) { + byte[] mac = peerIdToMacMap.get(rttPeer.peerHandle.peerId); + if (mac == null || mac.length != 6) { + Log.e(TAG, "processReceivedAwarePeerMacAddresses: received an invalid MAC " + + "address for peerId=" + rttPeer.peerHandle.peerId); + continue; + } newRequestBuilder.addResponder(new ResponderConfig( - MacAddress.fromBytes(peerIdToMacMap.get(rttPeer.peerHandle.peerId)), + MacAddress.fromBytes(mac), rttPeer.peerHandle, rttPeer.responderType, rttPeer.supports80211mc, rttPeer.channelWidth, rttPeer.frequency, rttPeer.centerFreq0, rttPeer.centerFreq1, rttPeer.preamble)); diff --git a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java index d1c1b028b..e1f35239f 100644 --- a/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/rtt/RttServiceImplTest.java @@ -305,13 +305,16 @@ public class RttServiceImplTest { RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0xA); PeerHandle peerHandle1 = new PeerHandle(1022); PeerHandle peerHandle2 = new PeerHandle(1023); + PeerHandle peerHandle3 = new PeerHandle(1024); request.mRttPeers.add(ResponderConfig.fromWifiAwarePeerHandleWithDefaults(peerHandle1)); request.mRttPeers.add(ResponderConfig.fromWifiAwarePeerHandleWithDefaults(peerHandle2)); + request.mRttPeers.add(ResponderConfig.fromWifiAwarePeerHandleWithDefaults(peerHandle3)); Map<Integer, MacAddress> peerHandleToMacMap = new HashMap<>(); MacAddress macAwarePeer1 = MacAddress.fromString("AA:BB:CC:DD:EE:FF"); MacAddress macAwarePeer2 = MacAddress.fromString("BB:BB:BB:EE:EE:EE"); peerHandleToMacMap.put(peerHandle1.peerId, macAwarePeer1); peerHandleToMacMap.put(peerHandle2.peerId, macAwarePeer2); + peerHandleToMacMap.put(peerHandle3.peerId, null); // bad answer from Aware (expired?) AwareTranslatePeerHandlesToMac answer = new AwareTranslatePeerHandlesToMac(mDefaultUid, peerHandleToMacMap); @@ -327,7 +330,8 @@ public class RttServiceImplTest { RangingRequest finalRequest = mRequestCaptor.getValue(); assertNotEquals("Request to native is not null", null, finalRequest); - assertEquals("Size of request", request.mRttPeers.size(), finalRequest.mRttPeers.size()); + assertEquals("Size of request", request.mRttPeers.size() - 1, + finalRequest.mRttPeers.size()); assertEquals("Aware peer 1 MAC", macAwarePeer1, finalRequest.mRttPeers.get(finalRequest.mRttPeers.size() - 2).macAddress); assertEquals("Aware peer 2 MAC", macAwarePeer2, @@ -1452,12 +1456,13 @@ public class RttServiceImplTest { Map<Integer, byte[]> result = new HashMap<>(); for (Integer peerId: peerIds) { - byte[] mac = mPeerIdToMacMap.get(peerId).toByteArray(); - if (mac == null) { - continue; + byte[] macBytes = null; + MacAddress macAddr = mPeerIdToMacMap.get(peerId); + if (macAddr != null) { + macBytes = macAddr.toByteArray(); } - result.put(peerId, mac); + result.put(peerId, macBytes); } try { |