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

java.net.URL allows to create URL with port < -1 and port > 65535

    XMLWordPrintable

Details

    • beta2
    • sparc
    • solaris_2.6

    Description



      Name: dfR10049 Date: 04/13/2001



      java.net.URL allows to create URL with port < -1 and port > 65535
      After the fix of 4101492 URL(protocol, host, port, file) checks whether port is not less
      than -1, but it still does not check for port is greater than 65535.

      URL(String spec) does not check the port value at all.

      Here is the test demonstrating the bug:

      ------------------------ Test.java ---------------------------------------
      import java.net.*;
      import java.io.*;


      public class Test {

          public static void main (String args[]){
             
              int[] ports = {
                      Integer.MIN_VALUE, Integer.MIN_VALUE + 1,
                      -2000, -3, -2,
                      65536, 65537, 100000,
                      Integer.MAX_VALUE - 1, Integer.MAX_VALUE
              };

              URL url = null;
              boolean passed = true;

              System.out.println("----- URL(String spec) ------");
              for (int i = 0; i < ports.length; i++) {
                  try {
                      url = new URL ("http://localhost:" + ports[i] + "/");
                      System.out.println("no exception with: " + ports[i]);
                      System.out.println(" url created: " + url);
                      passed = false;
                  } catch (Exception e) {
                  }
              }

              System.out.println("----- URL(proto, host, port, file) ------");

              for (int i = 0; i < ports.length; i++) {
                  try {
                      url = new URL ("http", "localhost", ports[i], "/file");
                      System.out.println("no exception with: " + ports[i]);
                      System.out.println(" url created: " + url);
                      passed = false;
                  } catch (Exception e) {
                  }
              }


              if (passed)
                  System.out.println("TEST PASSED ");
              else
                  System.out.println("TEST FAILED ");

          }
      }
      -----------------------------------------------------------------------------

      #> java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b60)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b60, mixed mode)


      #> java Test
      ----- URL(String spec) ------
      no exception with: -2147483648
          url created: http://localhost:-2147483648/
      no exception with: -2147483647
          url created: http://localhost:-2147483647/
      no exception with: -2000
          url created: http://localhost:-2000/
      no exception with: -3
          url created: http://localhost:-3/
      no exception with: -2
          url created: http://localhost:-2/
      no exception with: 65536
          url created: http://localhost:65536/
      no exception with: 65537
          url created: http://localhost:65537/
      no exception with: 100000
          url created: http://localhost:100000/
      no exception with: 2147483646
          url created: http://localhost:2147483646/
      no exception with: 2147483647
          url created: http://localhost:2147483647/
      ----- URL(proto, host, port, file) ------
      no exception with: 65536
          url created: http://localhost:65536/file
      no exception with: 65537
          url created: http://localhost:65537/file
      no exception with: 100000
          url created: http://localhost:100000/file
      no exception with: 2147483646
          url created: http://localhost:2147483646/file
      no exception with: 2147483647
          url created: http://localhost:2147483647/file
      TEST FAILED

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

      Attachments

        Activity

          People

            ywangsunw Yingxian Wang (Inactive)
            fdasunw Fda Fda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: