Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4460484

InetAddress.getByName() works incorrectly with illegal IPv6 addresses.

    Details

    • Subcomponent:
    • Resolved In Build:
      beta2
    • CPU:
      x86, sparc
    • OS:
      linux, solaris_2.6, windows_98
    • Verification:
      Verified

      Description



      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.

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              michaelm Michael McMahon
              Reporter:
              fdasunw Fda Fda (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: