mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-06-23 16:21:50 +00:00
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 catches the exception in get-multiaddr and returns an undefined value to listener rather than throwing an exception when trying to process defective or destroyed socket data. Listener then terminates processing of the incoming p2p connections that generate this error condition. fixes: https://github.com/libp2p/js-libp2p-tcp/issues/93 fixes: https://github.com/ipfs/js-ipfs/issues/1447
This commit is contained in:
@ -25,6 +25,15 @@ module.exports = (handler) => {
|
||||
socket.on('error', noop)
|
||||
|
||||
const addr = getMultiaddr(socket)
|
||||
if (!addr) {
|
||||
if (socket.remoteAddress === undefined) {
|
||||
log('connection closed before p2p connection made')
|
||||
} else {
|
||||
log('error interpreting incoming p2p connection')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
log('new connection', addr.toString())
|
||||
|
||||
const s = toPull.duplex(socket)
|
||||
|
Reference in New Issue
Block a user