Handle v4-mapped v6 address in Struct parsing Cherry-pick of aosp/2807798 to backport VPN security fix to non-mainline U devices. This CL removes test changes since u branches use module prebuilt by default. Having Merged-In to prevent automerger to udc-mainlie-prod where frameworks/libs/net does not exist. testV4MappedV6Address fails without change in Struct.java Bug: 193031925 Test: TH (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:80500a3de46b212c7ed0e9f9f9c87f698b101c17) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:338282075d51ef6402ddde764db12b6bafebc0c4) Merged-In: I2d0796b6deef1a2d9979f16ccc4afe9a04f028dc Change-Id: I2d0796b6deef1a2d9979f16ccc4afe9a04f028dc
diff --git a/common/device/com/android/net/module/util/Struct.java b/common/device/com/android/net/module/util/Struct.java index b638a46..9ae9abf 100644 --- a/common/device/com/android/net/module/util/Struct.java +++ b/common/device/com/android/net/module/util/Struct.java
@@ -414,7 +414,14 @@ final byte[] address = new byte[isIpv6 ? 16 : 4]; buf.get(address); try { - value = InetAddress.getByAddress(address); + if (isIpv6) { + // Using Inet6Address.getByAddress since InetAddress.getByAddress converts + // v4-mapped v6 address to v4 address internally and returns Inet4Address. + value = Inet6Address.getByAddress( + null /* host */, address, -1 /* scope_id */); + } else { + value = InetAddress.getByAddress(address); + } } catch (UnknownHostException e) { throw new IllegalArgumentException("illegal length of IP address", e); }