-
Bug
-
Resolution: Fixed
-
P2
-
1.1.4
-
1.2beta3
-
sparc
-
solaris_2.5
-
Verified
Name: yyC67448 Date: 11/11/97
The java.net.DatagramPacket.setData(byte[] ibuf) does not check if the
length of new buffer is greater than or equal to DatagramPacket.length.
JDK is missing documentation for this method.
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];
byte[] array = new byte[200];
array[0] = 22;
array[array.length -1] = 33;
try {
pac = new DatagramPacket(ar, ar.length);
} catch(Exception e)
{
System.out.println("Failed. Can not create DatagramPacket:" + e);
System.exit(-1);
}
try {
pac.setData(array);
} catch(Exception e)
{
System.out.println("Failed. Unexpected exception:" + e);
System.exit(-1);
}
if(pac.getLength() != array.length)
{
System.out.println("Failed. Buffer length mismatch");
System.exit(-1);
}
if(pac.getData()[0] == 22 && pac.getData()[pac.getData().length] == 33)
{
System.out.println("Passed. OKAY");
System.exit(0);
}
else
{
System.out.println("Failed. Data mismatch.");
System.exit(-1);
}
}
}
---------------------- Output from the test -----------------
Failed. Buffer length mismatch
-----------------------------------------------------------------
======================================================================