Repository navigation
ASN.1 parsing fix. - #23426
ASN.1 parsing fix.#23426monnerat wants to merge 2 commits into
Conversation
As a single element is parsed, the getASN1Element() returned pointer must then match the end of data.
There was a problem hiding this comment.
🟡 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.
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.
|
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 |
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. |
|
Thanks for merge. |

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.