lib: reject string "0" in validatePort when allowZero is false · nodejs/node@243b0e4 · GitHub
Skip to content

Commit 243b0e4

Browse files
watilderichardlau
authored andcommitted
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: #64174 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com>
1 parent a483bfd commit 243b0e4

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/internal/validators.js

Lines changed: 1 addition & 1 deletion

test/parallel/test-internal-validators-validateport.js

Lines changed: 14 additions & 0 deletions

0 commit comments

Comments
 (0)