mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-15 10:23:28 +00:00
8332686: InetAddress.ofLiteral can throw StringIndexOutOfBoundsException
Reviewed-by: dfuchs, jpai
This commit is contained in:
parent
56d315da48
commit
0c7451ae5a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2024, 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
|
||||
@ -554,6 +554,10 @@ class Inet6Address extends InetAddress {
|
||||
*/
|
||||
static InetAddress parseAddressString(String addressLiteral, boolean removeSqBrackets)
|
||||
throws UnknownHostException {
|
||||
// Empty strings are not parseable
|
||||
if (addressLiteral.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// Remove trailing and leading square brackets if requested
|
||||
if (removeSqBrackets && addressLiteral.charAt(0) == '[' &&
|
||||
addressLiteral.length() > 2 &&
|
||||
|
||||
@ -1618,6 +1618,9 @@ public sealed class InetAddress implements Serializable permits Inet4Address, In
|
||||
*/
|
||||
public static InetAddress ofLiteral(String ipAddressLiteral) {
|
||||
Objects.requireNonNull(ipAddressLiteral);
|
||||
if (ipAddressLiteral.isEmpty()) {
|
||||
throw IPAddressUtil.invalidIpAddressLiteral(ipAddressLiteral);
|
||||
}
|
||||
InetAddress inetAddress;
|
||||
try {
|
||||
// First try to parse the input as an IPv4 address literal
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 8272215 8315767
|
||||
* @bug 8272215 8315767 8332686
|
||||
* @summary Test for ofLiteral, ofPosixLiteral APIs in InetAddress classes
|
||||
* @run junit/othervm -Djdk.net.hosts.file=nonExistingHostsFile.txt
|
||||
* OfLiteralTest
|
||||
@ -373,7 +373,18 @@ public class OfLiteralTest {
|
||||
Arguments.of(InetAddressClass.INET4_ADDRESS_POSIX, ""), // empty
|
||||
Arguments.of(InetAddressClass.INET4_ADDRESS_POSIX, "0x1FFFFFFFF"), // 2^33 - 1 is too large
|
||||
Arguments.of(InetAddressClass.INET4_ADDRESS_POSIX, "0x100000000"), // 2^32 is too large
|
||||
Arguments.of(InetAddressClass.INET4_ADDRESS_POSIX, "040000000000")
|
||||
Arguments.of(InetAddressClass.INET4_ADDRESS_POSIX, "040000000000"),
|
||||
|
||||
// Empty literals
|
||||
Arguments.of(InetAddressClass.INET_ADDRESS, ""),
|
||||
Arguments.of(InetAddressClass.INET4_ADDRESS, ""),
|
||||
Arguments.of(InetAddressClass.INET6_ADDRESS, ""),
|
||||
|
||||
// Blank literals
|
||||
Arguments.of(InetAddressClass.INET_ADDRESS, " "),
|
||||
Arguments.of(InetAddressClass.INET4_ADDRESS, " "),
|
||||
Arguments.of(InetAddressClass.INET6_ADDRESS, " "),
|
||||
Arguments.of(InetAddressClass.INET4_ADDRESS_POSIX, " ")
|
||||
);
|
||||
// Construct arguments for a test case with IPv6-scoped address with scope-id
|
||||
// specified as a string with non-existing network interface name
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user