# HG changeset patch # User igerasim # Date 1521948103 25200 # Node ID 3c5c596ee0fdaa650d91dc0fada818d68d505e6b # Parent 7358ced1457423a7e99d2ff0e493678c6861cb2a 8195868: Address Internet Addresses Reviewed-by: chegar, rriggs, igerasim, skoivu, rhalade diff -r 7358ced14574 -r 3c5c596ee0fd src/share/classes/java/net/InetAddress.java --- a/src/share/classes/java/net/InetAddress.java Fri Jul 13 11:22:19 2018 -0700 +++ b/src/share/classes/java/net/InetAddress.java Sat Mar 24 20:21:43 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,7 @@ import java.io.ObjectStreamException; import java.io.ObjectStreamField; import java.io.IOException; +import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectInputStream.GetField; import java.io.ObjectOutputStream; @@ -1578,8 +1579,11 @@ } GetField gf = s.readFields(); String host = (String)gf.get("hostName", null); - int address= gf.get("address", 0); - int family= gf.get("family", 0); + int address = gf.get("address", 0); + int family = gf.get("family", 0); + if (family != IPv4 && family != IPv6) { + throw new InvalidObjectException("invalid address family type: " + family); + } InetAddressHolder h = new InetAddressHolder(host, address, family); UNSAFE.putObject(this, FIELDS_OFFSET, h); } diff -r 7358ced14574 -r 3c5c596ee0fd src/share/classes/java/net/NetworkInterface.java --- a/src/share/classes/java/net/NetworkInterface.java Fri Jul 13 11:22:19 2018 -0700 +++ b/src/share/classes/java/net/NetworkInterface.java Sat Mar 24 20:21:43 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -281,8 +281,20 @@ if (addr == null) { throw new NullPointerException(); } - if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) { - throw new IllegalArgumentException ("invalid address type"); + if (addr instanceof Inet4Address) { + Inet4Address inet4Address = (Inet4Address) addr; + if (inet4Address.holder.family != InetAddress.IPv4) { + throw new IllegalArgumentException("invalid family type: " + + inet4Address.holder.family); + } + } else if (addr instanceof Inet6Address) { + Inet6Address inet6Address = (Inet6Address) addr; + if (inet6Address.holder.family != InetAddress.IPv6) { + throw new IllegalArgumentException("invalid family type: " + + inet6Address.holder.family); + } + } else { + throw new IllegalArgumentException("invalid address type: " + addr); } return getByInetAddress0(addr); } diff -r 7358ced14574 -r 3c5c596ee0fd src/solaris/native/java/net/NetworkInterface.c --- a/src/solaris/native/java/net/NetworkInterface.c Fri Jul 13 11:22:19 2018 -0700 +++ b/src/solaris/native/java/net/NetworkInterface.c Sat Mar 24 20:21:43 2018 -0700 @@ -276,9 +276,21 @@ netif *ifs, *curr; jobject obj = NULL; jboolean match = JNI_FALSE; - int family = (getInetAddress_family(env, iaObj) == IPv4) ? AF_INET : AF_INET6; +#ifdef AF_INET6 + int family = getInetAddress_family(env, iaObj); JNU_CHECK_EXCEPTION_RETURN(env, NULL); + if (family == IPv4) { + family = AF_INET; + } else if (family == IPv6) { + family = AF_INET6; + } else { + return NULL; // Invalid family + } +#else + int family = AF_INET; +#endif + ifs = enumInterfaces(env); if (ifs == NULL) { return NULL;