From 478ed93a10c7c97725bdae1e5f263f17a56a280e Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 5 Jun 2020 13:46:48 -0400 Subject: [PATCH] Require complete MacAddressCompat --- .../main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt index f74f5409..f7b028a3 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt @@ -58,11 +58,13 @@ inline class MacAddressCompat(val addr: Long) { */ fun fromString(addr: String) = ByteBuffer.allocate(Long.SIZE_BYTES).run { order(ByteOrder.LITTLE_ENDIAN) - try { - put(addr.split(':').map { Integer.parseInt(it, 16).toByte() }.toByteArray()) + val bytes = try { + addr.split(':').map { Integer.parseInt(it, 16).toByte() }.toByteArray() } catch (e: NumberFormatException) { throw IllegalArgumentException(e) } + require(bytes.size == ETHER_ADDR_LEN) + put(bytes) rewind() MacAddressCompat(long) }