mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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>
This commit is contained in:
parent
7dc1a87a7b
commit
02ac302b6d
5 changed files with 39 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = { isLegalPort };
|
||||
module.exports = { isLegalPort, assertPort };
|
||||
|
||||
// Check that the port number is not NaN when coerced to a number,
|
||||
// is an integer and that it falls within the legal range of port numbers.
|
||||
|
@ -10,3 +10,9 @@ function isLegalPort(port) {
|
|||
return false;
|
||||
return +port === (+port >>> 0) && port <= 0xFFFF;
|
||||
}
|
||||
|
||||
|
||||
function assertPort(port) {
|
||||
if (typeof port !== 'undefined' && !isLegalPort(port))
|
||||
throw new RangeError('"port" argument must be >= 0 and < 65536');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue