Skip to content

Commit

Permalink
NPE protection primarily for access log
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed May 30, 2019
1 parent 1fa57f5 commit 65fb1ee
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions java/org/apache/tomcat/util/net/NioEndpoint.java
Expand Up @@ -1314,52 +1314,70 @@ public SendfileState processSendfile(SendfileDataBase sendfileData) {

@Override
protected void populateRemoteAddr() {
InetAddress inetAddr = getSocket().getIOChannel().socket().getInetAddress();
if (inetAddr != null) {
remoteAddr = inetAddr.getHostAddress();
SocketChannel sc = getSocket().getIOChannel();
if (sc != null) {
InetAddress inetAddr = sc.socket().getInetAddress();
if (inetAddr != null) {
remoteAddr = inetAddr.getHostAddress();
}
}
}


@Override
protected void populateRemoteHost() {
InetAddress inetAddr = getSocket().getIOChannel().socket().getInetAddress();
if (inetAddr != null) {
remoteHost = inetAddr.getHostName();
if (remoteAddr == null) {
remoteAddr = inetAddr.getHostAddress();
SocketChannel sc = getSocket().getIOChannel();
if (sc != null) {
InetAddress inetAddr = sc.socket().getInetAddress();
if (inetAddr != null) {
remoteHost = inetAddr.getHostName();
if (remoteAddr == null) {
remoteAddr = inetAddr.getHostAddress();
}
}
}
}


@Override
protected void populateRemotePort() {
remotePort = getSocket().getIOChannel().socket().getPort();
SocketChannel sc = getSocket().getIOChannel();
if (sc != null) {
remotePort = sc.socket().getPort();
}
}


@Override
protected void populateLocalName() {
InetAddress inetAddr = getSocket().getIOChannel().socket().getLocalAddress();
if (inetAddr != null) {
localName = inetAddr.getHostName();
SocketChannel sc = getSocket().getIOChannel();
if (sc != null) {
InetAddress inetAddr = sc.socket().getInetAddress();
if (inetAddr != null) {
localName = inetAddr.getHostName();
}
}
}


@Override
protected void populateLocalAddr() {
InetAddress inetAddr = getSocket().getIOChannel().socket().getLocalAddress();
if (inetAddr != null) {
localAddr = inetAddr.getHostAddress();
SocketChannel sc = getSocket().getIOChannel();
if (sc != null) {
InetAddress inetAddr = sc.socket().getInetAddress();

This comment has been minimized.

Copy link
@adityakadakia

adityakadakia Jul 16, 2019

getInetAddress() instead of getLocalAddress()
@markt-asf is this change intentional?

if (inetAddr != null) {
localAddr = inetAddr.getHostAddress();
}
}
}


@Override
protected void populateLocalPort() {
localPort = getSocket().getIOChannel().socket().getLocalPort();
SocketChannel sc = getSocket().getIOChannel();
if (sc != null) {
localPort = sc.socket().getLocalPort();
}
}


Expand Down

0 comments on commit 65fb1ee

Please sign in to comment.