提交 ced700db 编写于 作者: I igerasim

8195868: Address Internet Addresses

Reviewed-by: chegar, rriggs, igerasim, skoivu, rhalade
上级 a5af17b2
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -37,6 +37,7 @@ import java.security.AccessController; ...@@ -37,6 +37,7 @@ import java.security.AccessController;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.ObjectStreamField; import java.io.ObjectStreamField;
import java.io.IOException; import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectInputStream.GetField; import java.io.ObjectInputStream.GetField;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
...@@ -1602,8 +1603,11 @@ class InetAddress implements java.io.Serializable { ...@@ -1602,8 +1603,11 @@ class InetAddress implements java.io.Serializable {
} }
GetField gf = s.readFields(); GetField gf = s.readFields();
String host = (String)gf.get("hostName", null); String host = (String)gf.get("hostName", null);
int address= gf.get("address", 0); int address = gf.get("address", 0);
int family= gf.get("family", 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); InetAddressHolder h = new InetAddressHolder(host, address, family);
UNSAFE.putObject(this, FIELDS_OFFSET, h); UNSAFE.putObject(this, FIELDS_OFFSET, h);
} }
......
/* /*
* Copyright (c) 2000, 2013, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -319,8 +319,20 @@ public final class NetworkInterface { ...@@ -319,8 +319,20 @@ public final class NetworkInterface {
if (addr == null) { if (addr == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) { if (addr instanceof Inet4Address) {
throw new IllegalArgumentException ("invalid address type"); 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); return getByInetAddress0(addr);
} }
......
...@@ -335,10 +335,18 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0 ...@@ -335,10 +335,18 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
jobject obj = NULL; jobject obj = NULL;
jboolean match = JNI_FALSE; jboolean match = JNI_FALSE;
#if defined(AF_INET6) #if defined(AF_INET6)
int family = (getInetAddress_family(env, iaObj) == IPv4) ? AF_INET : AF_INET6; int family = getInetAddress_family(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, NULL); 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 #else
int family = AF_INET; int family = AF_INET;
#endif #endif
ifs = enumInterfaces(env); ifs = enumInterfaces(env);
if (ifs == NULL) { if (ifs == NULL) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册