8087190: Regression in sun.net.util.IPAddressUtil.isIPv4LiteralAddress(String)
Reviewed-by: chegar
This commit is contained in:
parent
f750dc8033
commit
9835141429
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2015, 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
|
||||
@ -44,6 +44,7 @@ public class IPAddressUtil {
|
||||
|
||||
long tmpValue = 0;
|
||||
int currByte = 0;
|
||||
boolean newOctet = true;
|
||||
|
||||
int len = src.length();
|
||||
if (len == 0 || len > 15) {
|
||||
@ -77,11 +78,12 @@ public class IPAddressUtil {
|
||||
for (int i = 0; i < len; i++) {
|
||||
char c = src.charAt(i);
|
||||
if (c == '.') {
|
||||
if (tmpValue < 0 || tmpValue > 0xff || currByte == 3) {
|
||||
if (newOctet || tmpValue < 0 || tmpValue > 0xff || currByte == 3) {
|
||||
return null;
|
||||
}
|
||||
res[currByte++] = (byte) (tmpValue & 0xff);
|
||||
tmpValue = 0;
|
||||
newOctet = true;
|
||||
} else {
|
||||
int digit = Character.digit(c, 10);
|
||||
if (digit < 0) {
|
||||
@ -89,9 +91,10 @@ public class IPAddressUtil {
|
||||
}
|
||||
tmpValue *= 10;
|
||||
tmpValue += digit;
|
||||
newOctet = false;
|
||||
}
|
||||
}
|
||||
if (tmpValue < 0 || tmpValue >= (1L << ((4 - currByte) * 8))) {
|
||||
if (newOctet || tmpValue < 0 || tmpValue >= (1L << ((4 - currByte) * 8))) {
|
||||
return null;
|
||||
}
|
||||
switch (currByte) {
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4749938
|
||||
* @bug 4749938 8087190
|
||||
* @summary Bug in the parsing IPv4 literal addresses
|
||||
* @modules java.base/sun.net.spi.nameservice
|
||||
* @compile -XDignore.symbol.file=true DummyNameService.java DummyNameServiceDescriptor.java
|
||||
@ -63,7 +63,11 @@ public class textToNumericFormat {
|
||||
"2380.255.255.255",
|
||||
"239.255.65536",
|
||||
"239.16777216",
|
||||
"4294967296" };
|
||||
"4294967296",
|
||||
".1.1.1",
|
||||
"1..1.1",
|
||||
"1.1.1.",
|
||||
"..." };
|
||||
|
||||
for (int i=0; i<goodAddrs.length; i++) {
|
||||
try {
|
||||
|
@ -21,6 +21,12 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8087190
|
||||
* @summary Exercise the sun.net.util.IPAddressUtil class
|
||||
*/
|
||||
|
||||
import sun.net.util.*;
|
||||
|
||||
/*
|
||||
@ -39,6 +45,10 @@ public class IPAddressUtilTest {
|
||||
{"238.255.2550.255", bad},
|
||||
{"238.2550.255.255", bad},
|
||||
{"2380.255.255.255", bad},
|
||||
{".1.1.1", bad},
|
||||
{"1..1.1", bad},
|
||||
{"1.1.1.", bad},
|
||||
{"...", bad},
|
||||
{"10::10", good},
|
||||
{"10::10.1", bad},
|
||||
{"10::10.1.2", bad},
|
||||
|
Loading…
x
Reference in New Issue
Block a user