mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8236105: Behaviors of DatagramSocket/DatagramChannel::socket send methods are not always consistent
DatagramSocket and MulticastSocket changed to throw IllegalArgumentException if not connected and passed a packet containing a port out of range Reviewed-by: chegar, dfuchs
This commit is contained in:
parent
fdbea219a1
commit
2f76772fa9
3 changed files with 259 additions and 6 deletions
|
@ -703,7 +703,7 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
* @throws IllegalArgumentException if the socket is connected,
|
||||
* and connected address and packet address differ, or
|
||||
* if the socket is not connected and the packet address
|
||||
* is not set.
|
||||
* is not set or if its port is out of range.
|
||||
*
|
||||
* @see java.net.DatagramPacket
|
||||
* @see SecurityManager#checkMulticast(InetAddress)
|
||||
|
@ -716,11 +716,14 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
if (isClosed())
|
||||
throw new SocketException("Socket is closed");
|
||||
InetAddress packetAddress = p.getAddress();
|
||||
int packetPort = p.getPort();
|
||||
checkAddress (packetAddress, "send");
|
||||
if (connectState == ST_NOT_CONNECTED) {
|
||||
if (packetAddress == null) {
|
||||
throw new IllegalArgumentException("Address not set");
|
||||
}
|
||||
if (packetPort < 0 || packetPort > 0xFFFF)
|
||||
throw new IllegalArgumentException("port out of range:" + packetPort);
|
||||
// check the address is ok with the security manager on every send.
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
|
||||
|
@ -733,7 +736,7 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
security.checkMulticast(packetAddress);
|
||||
} else {
|
||||
security.checkConnect(packetAddress.getHostAddress(),
|
||||
p.getPort());
|
||||
packetPort);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -742,7 +745,7 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
p.setAddress(connectedAddress);
|
||||
p.setPort(connectedPort);
|
||||
} else if ((!packetAddress.equals(connectedAddress)) ||
|
||||
p.getPort() != connectedPort) {
|
||||
packetPort != connectedPort) {
|
||||
throw new IllegalArgumentException("connected address " +
|
||||
"and packet address" +
|
||||
" differ");
|
||||
|
|
|
@ -726,7 +726,7 @@ public class MulticastSocket extends DatagramSocket {
|
|||
* @throws IllegalArgumentException if the socket is connected,
|
||||
* and connected address and packet address differ, or
|
||||
* if the socket is not connected and the packet address
|
||||
* is not set.
|
||||
* is not set or if its port is out of range.
|
||||
*
|
||||
*
|
||||
* @deprecated Use the following code or its equivalent instead:
|
||||
|
@ -750,11 +750,14 @@ public class MulticastSocket extends DatagramSocket {
|
|||
synchronized(ttlLock) {
|
||||
synchronized(p) {
|
||||
InetAddress packetAddress = p.getAddress();
|
||||
int packetPort = p.getPort();
|
||||
checkAddress(packetAddress, "send");
|
||||
if (connectState == ST_NOT_CONNECTED) {
|
||||
if (packetAddress == null) {
|
||||
throw new IllegalArgumentException("Address not set");
|
||||
}
|
||||
if (packetPort < 0 || packetPort > 0xFFFF)
|
||||
throw new IllegalArgumentException("port out of range:" + packetPort);
|
||||
// Security manager makes sure that the multicast address
|
||||
// is allowed one and that the ttl used is less
|
||||
// than the allowed maxttl.
|
||||
|
@ -764,7 +767,7 @@ public class MulticastSocket extends DatagramSocket {
|
|||
security.checkMulticast(packetAddress, ttl);
|
||||
} else {
|
||||
security.checkConnect(packetAddress.getHostAddress(),
|
||||
p.getPort());
|
||||
packetPort);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -773,7 +776,7 @@ public class MulticastSocket extends DatagramSocket {
|
|||
p.setAddress(connectedAddress);
|
||||
p.setPort(connectedPort);
|
||||
} else if ((!packetAddress.equals(connectedAddress)) ||
|
||||
p.getPort() != connectedPort) {
|
||||
packetPort != connectedPort) {
|
||||
throw new IllegalArgumentException("connected address and packet address" +
|
||||
" differ");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue