GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dns: fix crash on setServers with port 0 by lazerg · Pull Request #65009 · nodejs/node

Conversation

@lazerg

@lazerg 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lazerg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@lazerg
dns: fix crash on setServers with port 0
948d758
Signed-off-by: Lazizbek Ergashev <[email protected]>
@nodejs-github-bot

nodejs-github-bot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net
pckrishnadas88 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot 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
Renegade334
Renegade334 reviewed Aug 4, 2026
View reviewed changes
Comment thread src/cares_wrap.cc Resolved

Uh oh!

There was an error while loading. Please reload this page.

@lazerg
dns: keep type assertions in SetServers
42c89ee
Renegade334
Renegade334 approved these changes Aug 4, 2026
View reviewed changes

@Renegade334 Renegade334 left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

👍

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lazerg

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.

Renegade334 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Aug 4, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Aug 4, 2026
@Renegade334 Renegade334 added author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Aug 4, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Aug 4, 2026
@nodejs-github-bot

This comment was marked as outdated.

Sign in to view
@codecov

codecov Bot commented Aug 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Renegade334 Renegade334 mentioned this pull request Aug 4, 2026
dns: validate port range in setServers() #65021
Merged
@nodejs-github-bot

nodejs-github-bot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/75482/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Renegade334 Renegade334 added the commit-queue PRs queued for automated landing through the Commit Queue. label Aug 4, 2026
pimterry
pimterry approved these changes Aug 5, 2026
View reviewed changes
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Aug 6, 2026
@nodejs-github-bot
nodejs-github-bot merged commit ee64033 into nodejs:main Aug 6, 2026
79 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Landed in ee64033

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aduh95 pushed a commit that referenced this pull request Aug 13, 2026
@lazerg @aduh95
dns: fix crash on setServers with port 0
0b64b5d
Signed-off-by: Lazizbek Ergashev <[email protected]>
PR-URL: #65009
Fixes: #65006
Reviewed-By: René <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Tim Perry <[email protected]>
aduh95 pushed a commit that referenced this pull request Aug 25, 2026
@lazerg @aduh95
dns: fix crash on setServers with port 0
e9327d1
Signed-off-by: Lazizbek Ergashev <[email protected]>
PR-URL: #65009
Fixes: #65006
Reviewed-By: René <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Tim Perry <[email protected]>
@github-actions github-actions Bot mentioned this pull request Aug 25, 2026
2026-08-26, Version 26.8.0 (Current) #65551
Merged
aduh95 pushed a commit that referenced this pull request Aug 27, 2026
@lazerg @aduh95
dns: fix crash on setServers with port 0
37b9e9a
Signed-off-by: Lazizbek Ergashev <[email protected]>
PR-URL: #65009
Fixes: #65006
Reviewed-By: René <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Tim Perry <[email protected]>
@github-actions github-actions Bot mentioned this pull request Sep 7, 2026
2026-09-08, Version 24.21.0 'Krypton' (LTS) #65873
Merged
@robobun robobun mentioned this pull request Oct 29, 2026
dns: refuse setServers() ports above 65535 oven-sh/bun#47302
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@pimterry pimterry pimterry approved these changes
@Renegade334 Renegade334 Renegade334 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. 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 PRs the Commit Queue should land as one squashed commit. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@lazerg @nodejs-github-bot @mcollina @pimterry @Renegade334
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.