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

java.net.Socket.setSoLinger does not check second parameter for negative value

    XMLWordPrintable

Details

    • 1.2beta4
    • sparc
    • solaris_2.5
    • Verified

    Description



      Name: yyC67448 Date: 09/26/97



      The java.net.Socket.setSoLinger(boolean, int) does not check its second
      parameter for negative value when its first parameter is true.

      Here is the test demonstrating the bug:

      -------------------------------- Test.java -----------------------------

      import java.net.*;


      class test
      {

        public static void main(String args[])
        {
          InetAddress sin = null;
          Socket soc = null;
          int value = 0;


          /*
           * Try to get localhost address
           */
          try {
            sin = InetAddress.getLocalHost();
          } catch(Exception e)
          {
            System.out.println("Can not get localhost Address:" + e);
            System.exit(-1);
          }


          /*
           * Hope Telnet service enabled on localhost
           */
          try {
            soc = new Socket(sin, 23, true);
          } catch(Exception e)
          {
            System.out.println("Can not create socket:" + e);
            System.exit(-1);
          }

          /*
           * Try to set negative value
           */
          try {
            soc.setSoLinger(true, -20);
            value = soc.getSoLinger();
          } catch(IllegalArgumentException e)
          {
            try {
      soc.close();
            } catch(Exception e1)
            {
      System.out.println("Can not close socket:" + e1);
      System.exit(-1);
            }
            System.out.println("OKAY");
            System.exit(0);
          }
          catch(Exception e)
          {
            try {
      soc.close();
            } catch(Exception e1)
            {
      System.out.println("Can not close socket :" + e1);
      System.exit(-1);
            }
            System.out.println("Unexpected exception:" + e);
          }
          
          try {
            soc.close();
          } catch(Exception e)
          {
            System.out.println("Can not close socket:" + e);
            System.exit(-1);
          }

          System.out.println("No exceptions. Val = " + value);
          
        }
      }



      ---------------------- Output from the test -----------------
      No exceptions. Val = -20
      -----------------------------------------------------------------



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

      Attachments

        Activity

          People

            mmcclosksunw Michael Mccloskey (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: