mirror of https://github.com/lukechilds/node.git
Browse Source
Make sure we validate the port number in all kinds of `listen()` calls. Fixes: https://github.com/nodejs/node/issues/5727 PR-URL: https://github.com/nodejs/node/pull/5732 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>process-exit-stdio-flushing
Dirceu Pereira Tiegs
9 years ago
committed by
James M Snell
5 changed files with 39 additions and 20 deletions
@ -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); |
Loading…
Reference in new issue