diff options
author | James M Snell <jasnell@gmail.com> | 2016-03-16 06:46:53 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-03-21 22:08:57 +0300 |
commit | d0edabecbf072dded07f85897691b0ff1b0bb99b (patch) | |
tree | 94bd34ef0412869b2f0bc9191a59128f1bbf5063 /lib/internal/net.js | |
parent | 287bdabe407bcfae7a82f0189351ac0191d6e4d1 (diff) |
net: strict checking for internal/net isLegalPort
Add stricter testing for the isLegalPort method in internal/net.
This ensures that odd inputs such as isLegalPort(true) and
isLegalPort([1]) aren't acceptable as valid port inputs.
PR-URL: https://github.com/nodejs/node/pull/5733
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'lib/internal/net.js')
-rw-r--r-- | lib/internal/net.js | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/internal/net.js b/lib/internal/net.js index effc6485d25..30bd50ce937 100644 --- a/lib/internal/net.js +++ b/lib/internal/net.js @@ -5,7 +5,8 @@ module.exports = { isLegalPort }; // 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. function isLegalPort(port) { - if (typeof port === 'string' && port.trim() === '') + if ((typeof port !== 'number' && typeof port !== 'string') || + (typeof port === 'string' && port.trim().length === 0)) return false; - return +port === (port >>> 0) && port >= 0 && port <= 0xFFFF; + return +port === (+port >>> 0) && port <= 0xFFFF; } |