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

java.net.DatagramPacket constructor allows length < 0

XMLWordPrintable

    • 1.2beta3
    • sparc
    • solaris_2.5
    • Verified



      Name: yyC67448 Date: 11/11/97



      The constructor java.net.DatagramPacket(byte[], int) does not check it's second
      parameter (length) for negative values.


      Here is the test demonstrating the bug:

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


      class test
      {

        public static void main(String args[])
        {
          DatagramPacket pac = null;
          byte[] array = new byte[20];
          int len = -10;
          
          try {
            pac = new DatagramPacket(array, len);
          } catch(IllegalArgumentException e)
          {
            System.out.println("OKAY");
            System.exit(0);
          }
          catch(Exception e)
          {
            System.out.println("Failed. Can not create DatagramPacket:" + e);
            System.exit(-1);
          }
          
          System.out.println("Failed. No Exceptions.");

        }

      }

      ---------------------- Output from the test -----------------
      Failed. No Exceptions.
      -----------------------------------------------------------------
      ======================================================================

            brenaudsunw Benjamin Renaud (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: