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

DatagramPacket.setLength(int length) does not check length for negative values

    XMLWordPrintable

Details

    • 1.2beta3
    • sparc
    • solaris_2.5
    • Verified

    Description



      Name: yyC67448 Date: 11/11/97



      The java.net.DatagramPacket.setLength(int length) method does not check
      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[] ar = new byte[10];
          int len = -2;

          try {
            pac = new DatagramPacket(ar, ar.length);
          } catch(Exception e)
          {
            System.out.println("Failed. Can not create DatagramPacket:" + e);
            System.exit(-1);
          }
          
          try {
            pac.setLength(len);
          } catch(IllegalArgumentException e)
          {
              System.out.println("OKAY");
      System.exit(0);
          }
          catch(Exception e)
          {
            System.out.println("Failed. Unexpected exception:" + e);
            System.exit(-1);
          }
          
          System.out.println("Failed. No exceptions.");

        }

      }

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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: