From b2aebde690209767251f56185720e71dd9a05e1f Mon Sep 17 00:00:00 2001 From: TomCoded Date: Mon, 23 Jul 2018 03:48:26 +0000 Subject: [PATCH] fix: "invalid ip address" "daemon can be crashed by remote user" Per the nodeJS documentation, a Net socket.remoteAddress value may be undefined if the socket is destroyed, as by a client disconnect. A multiaddr cannot be created for an invalid IP address (such as the undefined remote address of a destroyed socket). Currently the attempt results in a crash that can be triggered remotely. This commit terminates processing of a destroyed socket before multiaddr causes the crash. fixes: https://github.com/libp2p/js-libp2p-tcp/issues/93 fixes: https://github.com/ipfs/js-ipfs/issues/1447 --- src/listener.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/listener.js b/src/listener.js index f04b6e5..4bd5529 100644 --- a/src/listener.js +++ b/src/listener.js @@ -24,6 +24,12 @@ module.exports = (handler) => { // Avoid uncaught errors cause by unstable connections socket.on('error', noop) + if (socket.remoteAddress===undefined + || socket.remotePort===undefined) { + log("connection closed before p2p connection made") + return + } + const addr = getMultiaddr(socket) log('new connection', addr.toString())