Skip to content

ASN.1 parsing fix. - #23426

Closed
monnerat wants to merge 2 commits into
curl:masterfrom
monnerat:eoc
Closed

monnerat wants to merge 2 commits into
curl:masterfrom
monnerat:eoc

Conversation

@monnerat

Copy link
Copy Markdown
Contributor

For 13 years, the ASN.1 parser wrongly handled the end of an unbounded element.
This tends to demonstrate elements are always bounded in the real world. Although defined in the ASN.1 specification, unbounded elements are not properly handled by OpenSSL and the latter never produces such elements.
Because we support them anyway, curl's code has to be correct, even if never used (alternative is to remove the feature, but the size gain would be less than tiny).

The first commit in this PR adds a check in unit test 1657 for that case.
The 2nd commit fixes the problem.

Thanks for considering it.

As a single element is parsed, the getASN1Element() returned pointer
must then match the end of data.

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.

🟡 Changes recommended

Truncated input can cause undefined pointer arithmetic before the bounds check runs.

1 open finding
What changed in this PR

Corrects handling of indefinite-length ASN.1 elements in curl’s certificate parser.

Changes:

  • Validates and consumes the two-byte end-of-contents marker.
  • Strengthens unit1657 to check that parsing consumes the full input.
File Description
tests/​unit/​unit1657.c Checks the returned parser position.
lib/​vtls/​x509asn1.c Corrects end-marker handling and adjusts recursion bookkeeping.

🧠 Review effort: Balanced


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

Comment thread lib/vtls/x509asn1.c Resolved
When encountering an unbounded element, getASN1Element() parses the
content until it finds an EOC element and skips the latter that should
be 2 null bytes. The function before this commit wrongly considers an
EOC is a single byte and thus returns a misaligned pointer.
@testclutch

Copy link
Copy Markdown

Analysis of PR #23426 at eb4205b7:

Test ../../tests/http/test_03_goaway.py::TestGoAway::test_03_01_h2_goaway failed, which has NOT been flaky recently, so there could be a real issue in this PR.

Generated by Testclutch

@monnerat

Copy link
Copy Markdown
Contributor Author

Test ../../tests/http/test_03_goaway.py::TestGoAway::test_03_01_h2_goaway failed, which has NOT been flaky recently, so there could be a real issue in this PR

This PR only touches ASN.1 parsing that should not even be attempted by the pertaining test. The modified unit test does not even try to connect.
Running the goaway test manually on my workstation succeeds.
IMO this is an unrelated failure.

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 changes address the parsing error with bounds-safe handling and a targeted regression check; no unresolved issues remain.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@monnerat

Copy link
Copy Markdown
Contributor Author

Thanks for merge.

@monnerat
monnerat deleted the eoc branch October 23, 2026 11:13
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.

4 participants