From 9e7dd238a44140ae388637d6ce025ed4893a2636 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Mon, 6 Apr 2009 19:43:54 +0000
Subject: [PATCH] prevent NPE

---
 .../net/i2p/router/transport/ntcp/EstablishState.java    | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/router/java/src/net/i2p/router/transport/ntcp/EstablishState.java b/router/java/src/net/i2p/router/transport/ntcp/EstablishState.java
index 942d6cbc99..f8ccf0814d 100644
--- a/router/java/src/net/i2p/router/transport/ntcp/EstablishState.java
+++ b/router/java/src/net/i2p/router/transport/ntcp/EstablishState.java
@@ -462,7 +462,6 @@ public class EstablishState {
                     if (!_verified) {
                         _context.statManager().addRateData("ntcp.invalidSignature", 1, 0);
                         fail("Signature was invalid - attempt to spoof " + _con.getRemotePeer().calculateHash().toBase64() + "?");
-                        return;
                     } else {
                         if (_log.shouldLog(Log.DEBUG))
                             _log.debug(prefix() + "signature verified from Bob.  done!");
@@ -472,10 +471,12 @@ public class EstablishState {
                         byte nextReadIV[] = new byte[16];
                         System.arraycopy(_e_bobSig, _e_bobSig.length-16, nextReadIV, 0, nextReadIV.length);
                         _con.finishOutboundEstablishment(_dh.getSessionKey(), (_tsA-_tsB), nextWriteIV, nextReadIV); // skew in seconds
-                       _transport.setIP(_con.getRemotePeer().calculateHash(),
-                                        _con.getChannel().socket().getInetAddress().getAddress());
-                        return;
+                        // if socket gets closed this will be null - prevent NPE
+                        InetAddress ia = _con.getChannel().socket().getInetAddress();
+                        if (ia != null)
+                            _transport.setIP(_con.getRemotePeer().calculateHash(), ia.getAddress());
                     }
+                    return;
                 }
             }
         }
-- 
GitLab