FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

dns: fix crash on setServers with port 0 by lazerg · Pull Request #65009 · nodejs/node · GitHub

/ node Public

dns: fix crash on setServers with port 0 - #65009

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
lazerg:fix/issue-65006-setservers-port-zero
Aug 6, 2026
Merged

dns: fix crash on setServers with port 0#65009
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
lazerg:fix/issue-65006-setservers-port-zero

Conversation

lazerg commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

dns.setServers(['1.1.1.1:0']) aborts the process:

Assertion failed: portValue->Int32Value(env->context()).FromJust()

SetServers() in src/cares_wrap.cc checked the port with CHECK(portValue->Int32Value(env->context()).FromJust()). That asserts the port value is non-zero, not that the conversion succeeded, so a port of 0 trips it. The family value had the same problem. Both now use Maybe::To(), like the rest of the file.

c-ares already treats port 0 as "use the default port", so 1.1.1.1:0 becomes 1.1.1.1:53. [::1]:0 behaved that way already, since the bracketed-IPv6 branch in lib/internal/dns/utils.js coerces 0 to 53 before it ever reaches C++.

Fixes: #65006

Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com>

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. needs-ci PRs that need a full CI run. labels Aug 4, 2026
Comment thread src/cares_wrap.cc

Renegade334 left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

👍

Note that this preserves the previous behaviour of crashing the process if the port was greater than INT_MAX. Indeed, even below that point, any port value greater than 65535 overflows:

> dns.setServers(['1.1.1.1:65535', '1.1.1.1:65536', '1.1.1.1:65537'])
> dns.getServers()
[ '1.1.1.1:65535', '1.1.1.1', '1.1.1.1:1' ]

If you're happy, I think it would be a worthwhile addition to add validation to the port values, either as part of this PR or as a follow-up PR?

lazerg commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I couldn't reproduce the wraparound though — on this branch (c-ares 1.34.8, bundled, untouched by this diff):

> dns.setServers(['1.1.1.1:65535', '1.1.1.1:65536', '1.1.1.1:65537'])
Uncaught Error [ERR_DNS_SET_SERVERS_FAILED]: c-ares failed to set servers: "Misformatted string" [...]

ares_parse_port() (deps/cares/src/lib/str/ares_str.c) already caps at 65535 via ares_str_parse_uint(str, 65535UL, &val), so the CSV parse fails and the whole call throws, restoring the previous server list. That check is unrelated to this PR's diff, so it should behave the same on main.

Might be version-dependent on your end. Since I can't reproduce silent corruption on the current bundled c-ares, I'd rather not scope-creep this PR with validatePort() unless you still want the earlier/clearer JS-side error as its own improvement — happy to open that as a follow-up if so.

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm

mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 4, 2026
Renegade334 added author ready PRs that have at least one approval, no outstanding review comments, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Aug 4, 2026
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 4, 2026

This comment was marked as outdated.

codecov Bot commented Aug 4, 2026
edited
Loading

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.29%. Comparing base (ece8bbe) to head (42c89ee).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
src/cares_wrap.cc 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65009      +/-   ##
==========================================
- Coverage   90.29%   90.29%   -0.01%     
==========================================
  Files         762      759       -3     
  Lines      247646   247605      -41     
  Branches    46709    46672      -37     
==========================================
- Hits       223619   223564      -55     
- Misses      15485    15516      +31     
+ Partials     8542     8525      -17     
Files with missing lines Coverage Δ
src/cares_wrap.cc 62.93% <50.00%> (ø)

... and 54 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator

Renegade334 added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 4, 2026
nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 6, 2026
nodejs-github-bot merged commit ee64033 into nodejs:main Aug 6, 2026
79 checks passed

Copy link
Copy Markdown
Collaborator

Landed in ee64033

aduh95 pushed a commit that referenced this pull request Aug 13, 2026
Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com>
PR-URL: #65009
Fixes: #65006
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
aduh95 pushed a commit that referenced this pull request Aug 25, 2026
Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com>
PR-URL: #65009
Fixes: #65006
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. cares Issues and PRs related to the c-ares dependency or the cares_wrap binding. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dns.setServers.apply triggers SIGABRT when passed an address with port 0

5 participants


Back | FazBrowse Home | New Git URL