[#2262] Fix NPE triggered by unresolveable InetSocketAddress in epoll transport
Motivation: At the moment when an unresolvable InetSocketAddress is passed into the epoll transport a NPE is thrown Modifications: Add check in place which will throw an UnknownHostException if an InetSocketAddress could not been resolved. Result: Proper handling of unresolvable InetSocketAddresses
This commit is contained in:
parent
ef53227836
commit
5fa29f9a53
@ -23,6 +23,7 @@ import io.netty.channel.EventLoop;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
abstract class AbstractEpollChannel extends AbstractChannel {
|
||||
private static final ChannelMetadata DATA = new ChannelMetadata(false);
|
||||
@ -128,6 +129,12 @@ abstract class AbstractEpollChannel extends AbstractChannel {
|
||||
@Override
|
||||
protected abstract AbstractEpollUnsafe newUnsafe();
|
||||
|
||||
protected static void checkResolvable(InetSocketAddress addr) throws UnknownHostException {
|
||||
if (addr.isUnresolved()) {
|
||||
throw new UnknownHostException("Unable to resolve addr " + addr);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract class AbstractEpollUnsafe extends AbstractUnsafe {
|
||||
protected boolean readPending;
|
||||
|
||||
|
@ -50,6 +50,7 @@ public final class EpollServerSocketChannel extends AbstractEpollChannel impleme
|
||||
@Override
|
||||
protected void doBind(SocketAddress localAddress) throws Exception {
|
||||
InetSocketAddress addr = (InetSocketAddress) localAddress;
|
||||
checkResolvable(addr);
|
||||
Native.bind(fd, addr.getAddress(), addr.getPort());
|
||||
local = addr;
|
||||
Native.listen(fd, config.getBacklog());
|
||||
|
@ -41,6 +41,7 @@ import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -528,11 +529,13 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So
|
||||
*/
|
||||
private boolean doConnect(InetSocketAddress remoteAddress, InetSocketAddress localAddress) throws Exception {
|
||||
if (localAddress != null) {
|
||||
checkResolvable(localAddress);
|
||||
Native.bind(fd, localAddress.getAddress(), localAddress.getPort());
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
try {
|
||||
checkResolvable(remoteAddress);
|
||||
boolean connected = Native.connect(fd, remoteAddress.getAddress(),
|
||||
remoteAddress.getPort());
|
||||
if (!connected) {
|
||||
|
Loading…
Reference in New Issue
Block a user