- 
    Type:
Bug
 - 
    Resolution: Fixed
 - 
    Priority:
  P3                     
     - 
    Affects Version/s: 1.4.0
 - 
    Component/s: core-libs
 
- 
        beta2
 - 
        x86, sparc
 - 
        linux, solaris_2.6, windows_98
 - 
        Verified
 
Name: dfR10049 Date: 05/18/2001
java.net.InetAddress.getByName(host) works incorrectly with illegal IPv6 addresses
if SecurityManager is set. It throws IllegalArgumentException instead of
UnknownHostException.
This is the test demonstrating the bug:
------------------------------------------------------
import java.net.*;
import java.io.*;
public class Test {
public static void main (String args[]){
SecurityManager sm = new SecurityManager();
String strAddr = "::FFFF:127.0.0.1.2";
System.out.println("SecurityManager is not set ");
try {
InetAddress addr = InetAddress.getByName(strAddr);
} catch (Exception e) {
e.printStackTrace(System.out);
}
System.out.println("==================================");
System.out.println("SecurityManager is set ");
System.setSecurityManager(sm);
try {
InetAddress addr = InetAddress.getByName(strAddr);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
------------------------------------------------------
output from the test:
#> java Test
SecurityManager is not set
java.net.UnknownHostException: ::FFFF:127.0.0.1.2
at java.net.InetAddress.getAllByName0(InetAddress.java:778)
at java.net.InetAddress.getAllByName0(InetAddress.java:748)
at java.net.InetAddress.getAllByName(InetAddress.java:742)
at java.net.InetAddress.getByName(InetAddress.java:679)
at Test.main(Test.java:15)
==================================
SecurityManager is set
java.lang.IllegalArgumentException: invalid port range: :FFFF:127.0.0.1.2
at java.net.SocketPermission.init(SocketPermission.java:317)
at java.net.SocketPermission.<init>(SocketPermission.java:207)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1042)
at java.net.InetAddress.getAllByName0(InetAddress.java:767)
at java.net.InetAddress.getAllByName0(InetAddress.java:748)
at java.net.InetAddress.getAllByName(InetAddress.java:742)
at java.net.InetAddress.getByName(InetAddress.java:679)
at Test.main(Test.java:26)
The reason of this bug is if SecurityManager is set then SocketPermission ctor is
invoked by checkConnect() method. But checkConnect() does not enclose host in []
before pass to SocketPermission.
======================================================================