Skip to content

dnscache: compare full hostnames when lookup keys are truncated - #23350

Closed
cla7aye15I4nd wants to merge 5 commits into
curl:masterfrom
cla7aye15I4nd:zheng/curl-dns-hostname
Closed

cla7aye15I4nd wants to merge 5 commits into
curl:masterfrom
cla7aye15I4nd:zheng/curl-dns-hostname

Conversation

@cla7aye15I4nd

@cla7aye15I4nd cla7aye15I4nd commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

A cached 255-byte hostname can match a longer hostname sharing the truncated hash key. Require both names to fit the key before using the fast path; otherwise compare the complete case-insensitive hostname. Extend unit3271 with both length orderings and equal long names.

Validation: unit3271 passes. A local HTTP reproducer using a 255-byte CURLOPT_RESOLVE entry no longer receives a request for the longer .evil hostname (CURLE_COULDNT_RESOLVE_HOST). Existing resolve tests pass.

Prepared against upstream master (b8f71d6e1199701352c498467c17847237d1c43e). AI-assisted patch, independently reviewed and tested locally. Source-format checks pass; cross-platform CI remains to be reviewed.

@github-actions github-actions Bot added the tests label Oct 11, 2026
Comment thread lib/vdns/dnscache.c Resolved
Comment thread tests/unit/unit3271.c Resolved
@cla7aye15I4nd cla7aye15I4nd changed the title dnscache: compare full hostnames when lookup keys are truncated [WIP] dnscache: compare full hostnames when lookup keys are truncated Oct 11, 2026
@cla7aye15I4nd cla7aye15I4nd changed the title [WIP] dnscache: compare full hostnames when lookup keys are truncated dnscache: compare full hostnames when lookup keys are truncated Oct 11, 2026
@cla7aye15I4nd
cla7aye15I4nd marked this pull request as ready for review October 11, 2026 08:18
@bagder
bagder requested a balanced review from Copilot October 11, 2026 21:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fix correctly handles truncated keys and includes appropriate regression tests.

0 open findings

What changed in this PR

Hardens DNS cache lookup against collisions caused by truncated hostname keys.

Changes:

  • Requires full hostname comparison when either cache key is truncated.
  • Adds tests for long-hostname ordering, equality, and case insensitivity.
File Description
lib/​vdns/​dnscache.c Corrects truncated-key hostname matching.
tests/​unit/​unit3271.c Adds long-hostname regression coverage.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bagder
bagder requested a review from icing October 13, 2026 08:42

@icing icing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch. I only fixed the one direction.

Comment thread tests/unit/unit3271.c Resolved
Co-authored-by: Jay Satiro <raysatiro@yahoo.com>
@cla7aye15I4nd
cla7aye15I4nd requested a review from jay October 13, 2026 20:02
Prepare the short cached hostname in the local array to avoid a constant out-of-bounds subscript on the trailing one-element member.

Validation: macOS arm64 AppleClang 21 Debug unit3271 passes; checksrc and git diff --check pass. CURL_WERROR enabled with an exception for an unrelated socketpair.c unreachable-code warning. Older MinGW validation is left to CI.
@jay jay closed this in e6dec1f Oct 14, 2026
@jay

jay commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

5 participants