forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: Validate port in createServer().listen()
Make sure we validate the port number in all kinds of `listen()` calls. Fixes: nodejs#5727
- Loading branch information
Showing
5 changed files
with
39 additions
and
20 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
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,27 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
const invalidPort = -1 >>> 0; | ||
const errorMessage = /"port" argument must be \>= 0 and \< 65536/; | ||
|
||
net.Server().listen(common.PORT, function() { | ||
assert.equal(this._connectionKey, '6::::' + common.PORT); | ||
this.close(); | ||
}); | ||
|
||
// The first argument is a configuration object | ||
assert.throws(() => { | ||
net.Server().listen({ port: invalidPort }, common.fail); | ||
}, errorMessage); | ||
|
||
// The first argument is the port, no IP given. | ||
assert.throws(() => { | ||
net.Server().listen(invalidPort, common.fail); | ||
}, errorMessage); | ||
|
||
// The first argument is the port, the second an IP. | ||
assert.throws(() => { | ||
net.Server().listen(invalidPort, '0.0.0.0', common.fail); | ||
}, errorMessage); |
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