Fix bug in MacAddress.fromString()

Test: runtest frameworks-net
Bug: 69390696
Change-Id: I83f01e4915092e08ed201d9b6738bb02498d3bba
This commit is contained in:
Hugo Benichi
2017-12-05 13:14:08 +09:00
parent 98ecd7efb2
commit 21c7a52042
2 changed files with 5 additions and 3 deletions

View File

@@ -280,9 +280,8 @@ public final class MacAddress implements Parcelable {
throw new IllegalArgumentException(addr + " was not a valid MAC address"); throw new IllegalArgumentException(addr + " was not a valid MAC address");
} }
long longAddr = 0; long longAddr = 0;
int index = ETHER_ADDR_LEN; for (int i = 0; i < parts.length; i++) {
while (index-- > 0) { int x = Integer.valueOf(parts[i], 16);
int x = Integer.valueOf(parts[index], 16);
if (x < 0 || 0xff < x) { if (x < 0 || 0xff < x) {
throw new IllegalArgumentException(addr + "was not a valid MAC address"); throw new IllegalArgumentException(addr + "was not a valid MAC address");
} }

View File

@@ -161,6 +161,9 @@ public class MacAddressTest {
assertEquals(mac, MacAddress.fromString(stringRepr)); assertEquals(mac, MacAddress.fromString(stringRepr));
assertEquals(mac, MacAddress.fromBytes(bytesRepr)); assertEquals(mac, MacAddress.fromBytes(bytesRepr));
assertEquals(mac, MacAddress.fromString(MacAddress.stringAddrFromByteAddr(bytesRepr)));
assertEquals(mac, MacAddress.fromBytes(MacAddress.byteAddrFromStringAddr(stringRepr)));
} }
} }