Commit 3796b48
lib: fix validatePort to reject string '0' when allowZero is false
The `port === 0 && !allowZero` check used strict equality, so the
string `'0'` (and other numeric-zero string forms like `'0x0'`) slipped
through because `'0' === 0` is `false`. As a result,
`validatePort('0', name, false)` returned `0`, contradicting the
`allowZero=false` contract and letting callers such as
`dgram.Socket#connect('0', ...)` proceed past the validator and fail
deep in the stack with `EADDRNOTAVAIL` while leaking the handle.
Compare the numeric coercion (`+port === 0`) so all numeric-zero forms
are rejected consistently.
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: DeepView Autofix <[email protected]>
Co-Authored-By: Nikita Skovoroda <[email protected]>
Signed-off-by: Nikita Skovoroda <[email protected]>1 parent 14e16db commit 3796b48
3 files changed
Lines changed: 9 additions & 2 deletions
File tree
- lib/internal
- test/parallel
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
431 | | - | |
| 431 | + | |
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
0 commit comments