Skip to content

Commit 9370155

Browse files
committed
fix: invalid ip address and 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: libp2p#93 fixes: ipfs/js-ipfs#1447
1 parent d39ec2d commit 9370155

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/listener.js

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ module.exports = (handler) => {
2424
// Avoid uncaught errors cause by unstable connections
2525
socket.on('error', noop)
2626

27+
if (socket.remoteAddress === undefined ||
28+
socket.remotePort === undefined) {
29+
log('connection closed before p2p connection made')
30+
return
31+
}
32+
2733
const addr = getMultiaddr(socket)
2834
log('new connection', addr.toString())
2935

0 commit comments

Comments
 (0)