mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
lib: reject string "0" in validatePort when allowZero is false
The allowZero guard compared the raw value with `port === 0`, but
validatePort accepts strings and coerces them with `+port` in every
other clause. Since `'0' === 0` is false, string forms of zero
('0', ' 0 ', '00', '0x0', ...) slipped past the guard when
allowZero was false, while the numeric 0 was correctly rejected.
This is reachable via dgram's send(), connect(), and bind(), which
call validatePort(port, 'Port', false): passing '0' was silently
accepted instead of throwing ERR_SOCKET_BAD_PORT.
Coerce the value with `+port` so the zero check matches the rest of
the validation.
Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64174
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
This commit is contained in:
1 parent
dd4482e915
commit
af9ea9cfcf
2 files changed
+15
-1
No files matched your search
@@ -438,7 +438,7 @@ const validatePort = hideStackFrames((port, name = 'Port', allowZero = true) =>
|
||||
(typeof port === 'string' && StringPrototypeTrim(port).length === 0) ||
|
||||
+port !== (+port >>> 0) ||
|
||||
port > 0xFFFF ||
|
||||
(port === 0 && !allowZero)) {
|
||||
(+port === 0 && !allowZero)) {
|
||||
throw new ERR_SOCKET_BAD_PORT(name, port, allowZero);
|
||||
}
|
||||
return port | 0;
|
||||
|
||||
Reference in new issue
Block a user