summaryrefslogtreecommitdiff
path: root/lib/net.js
diff options
context:
space:
mode:
authorDirceu Pereira Tiegs <dirceutiegs@gmail.com>2016-03-15 20:34:19 -0300
committerJames M Snell <jasnell@gmail.com>2016-04-20 15:41:18 -0700
commit02ac302b6d08fad1ad02b71ca04259fb08294038 (patch)
treee78aa750bc0c90c9c7d7745dfc32fbeaabdef9ec /lib/net.js
parent7dc1a87a7b2ac8be34aa1e74643766cdc90c82d4 (diff)
downloadandroid-node-v8-02ac302b6d08fad1ad02b71ca04259fb08294038.tar.gz
android-node-v8-02ac302b6d08fad1ad02b71ca04259fb08294038.tar.bz2
android-node-v8-02ac302b6d08fad1ad02b71ca04259fb08294038.zip
net: Validate port in createServer().listen()
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>
Diffstat (limited to 'lib/net.js')
-rw-r--r--lib/net.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/net.js b/lib/net.js
index 3c87ac29d2..c2b3f5500a 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -24,6 +24,7 @@ var cluster;
const errnoException = util._errnoException;
const exceptionWithHostPort = util._exceptionWithHostPort;
const isLegalPort = internalNet.isLegalPort;
+const assertPort = internalNet.assertPort;
function noop() {}
@@ -1352,9 +1353,7 @@ Server.prototype.listen = function() {
(typeof h.port === 'undefined' && 'port' in h)) {
// Undefined is interpreted as zero (random port) for consistency
// with net.connect().
- if (typeof h.port !== 'undefined' && !isLegalPort(h.port))
- throw new RangeError('"port" option should be >= 0 and < 65536: ' +
- h.port);
+ assertPort(h.port);
if (h.host)
listenAfterLookup(h.port | 0, h.host, backlog, h.exclusive);
else
@@ -1375,10 +1374,12 @@ Server.prototype.listen = function() {
typeof arguments[1] === 'function' ||
typeof arguments[1] === 'number') {
// The first argument is the port, no IP given.
+ assertPort(port);
listen(self, null, port, 4, backlog);
} else {
// The first argument is the port, the second an IP.
+ assertPort(port);
listenAfterLookup(port, arguments[1], backlog);
}