mirror of
https://github.com/openjdk/jdk15u.git
synced 2025-12-13 02:34:18 -06:00
8293598: Enhance InetAddress address handling
Reviewed-by: bae Backport-of: a2668f58ccc3b7c7d74e2903128b08d97aac5798
This commit is contained in:
parent
5c1a24f7da
commit
5a0cbd1d89
@ -1359,6 +1359,10 @@ public class InetAddress implements java.io.Serializable {
|
|||||||
InetAddress[] ret = new InetAddress[1];
|
InetAddress[] ret = new InetAddress[1];
|
||||||
if(addr != null) {
|
if(addr != null) {
|
||||||
if (addr.length == Inet4Address.INADDRSZ) {
|
if (addr.length == Inet4Address.INADDRSZ) {
|
||||||
|
if (numericZone != -1 || ifname != null) {
|
||||||
|
// IPv4-mapped address must not contain zone-id
|
||||||
|
throw new UnknownHostException(host + ": invalid IPv4-mapped address");
|
||||||
|
}
|
||||||
ret[0] = new Inet4Address(null, addr);
|
ret[0] = new Inet4Address(null, addr);
|
||||||
} else {
|
} else {
|
||||||
if (ifname != null) {
|
if (ifname != null) {
|
||||||
@ -1403,22 +1407,23 @@ public class InetAddress implements java.io.Serializable {
|
|||||||
int percent = s.indexOf ('%');
|
int percent = s.indexOf ('%');
|
||||||
int slen = s.length();
|
int slen = s.length();
|
||||||
int digit, zone=0;
|
int digit, zone=0;
|
||||||
|
int multmax = Integer.MAX_VALUE / 10; // for int overflow detection
|
||||||
if (percent == -1) {
|
if (percent == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for (int i=percent+1; i<slen; i++) {
|
for (int i=percent+1; i<slen; i++) {
|
||||||
char c = s.charAt(i);
|
char c = s.charAt(i);
|
||||||
if (c == ']') {
|
if ((digit = IPAddressUtil.parseAsciiDigit(c, 10)) < 0) {
|
||||||
if (i == percent+1) {
|
return -1;
|
||||||
/* empty per-cent field */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if ((digit = Character.digit (c, 10)) < 0) {
|
if (zone > multmax) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
zone = (zone * 10) + digit;
|
zone = (zone * 10) + digit;
|
||||||
|
if (zone < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return zone;
|
return zone;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -785,7 +785,7 @@ public class IPAddressUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse ASCII digit in given radix
|
// Parse ASCII digit in given radix
|
||||||
private static int parseAsciiDigit(char c, int radix) {
|
public static int parseAsciiDigit(char c, int radix) {
|
||||||
assert radix == OCTAL || radix == DECIMAL || radix == HEXADECIMAL;
|
assert radix == OCTAL || radix == DECIMAL || radix == HEXADECIMAL;
|
||||||
if (radix == HEXADECIMAL) {
|
if (radix == HEXADECIMAL) {
|
||||||
return parseAsciiHexDigit(c);
|
return parseAsciiHexDigit(c);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user