This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #93 fixes: ipfs/js-ipfs#1447
- Loading branch information
Showing
3 changed files
with
86 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const pull = require('pull-stream') | ||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
const getMultiaddr = require('../src/get-multiaddr') | ||
const multiaddr = require('multiaddr') | ||
|
||
const goodSocket4 = { | ||
remoteAddress: "127.0.0.1", | ||
remotePort: "9090", | ||
remoteFamily: "IPv4" | ||
} | ||
|
||
const goodSocket6 = { | ||
remoteAddress: "::1", | ||
remotePort: "9090", | ||
remoteFamily: "IPv6" | ||
} | ||
|
||
const badSocket = {} | ||
|
||
const badSocketData = { | ||
remoteAddress: "aewmrn4awoew", | ||
remotePort: "234", | ||
remoteFamily: "Hufflepuff" | ||
} | ||
|
||
describe('getMultiaddr multiaddr creation', () => { | ||
|
||
it('creates multiaddr from valid socket data', (done) => { | ||
expect(getMultiaddr(goodSocket4)) | ||
.to.exist() | ||
done() | ||
}) | ||
|
||
it('creates multiaddr from valid IPv6 socket data', (done) => { | ||
expect(getMultiaddr(goodSocket6)) | ||
.to.exist() | ||
done() | ||
}) | ||
|
||
it('returns undefined multiaddr from missing socket data', (done) => { | ||
expect(getMultiaddr(badSocket)) | ||
.to.equal(undefined) | ||
done() | ||
}) | ||
|
||
it('returns undefined multiaddr from unparseable socket data', (done) => { | ||
expect(getMultiaddr(badSocketData)) | ||
.to.equal(undefined) | ||
done() | ||
}) | ||
}) |