Fix DecodeAltNames length check#10024
Merged
dgarske merged 2 commits intowolfSSL:masterfrom Mar 20, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an integer underflow in DecodeAltNames() when parsing Subject Alternative Name (SAN) entries in the non-template ASN path, and adds a regression test to ensure malformed SAN lengths are rejected.
Changes:
- Added bounds checks before decrementing the remaining SEQUENCE length in
DecodeAltNames(). - Added an API-level regression test covering SAN length underflow.
- Registered the new test in the ASN test suite declarations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| wolfcrypt/src/asn.c | Adds bounds checks to prevent length underflow while decoding SAN entries. |
| tests/api/test_asn.h | Declares and registers the new regression test. |
| tests/api/test_asn.c | Adds a regression test certificate with malformed SAN length and a control certificate. |
Comments suppressed due to low confidence (2)
wolfcrypt/src/asn.c:1
- The bounds check is performed after the entry has already been added to the certificate. On malformed input this can leave partially-populated alt-name state in
cert(and potentially allocate/link nodes) even though the function returns an error. Consider moving thestrLen > lengthcheck to occur beforeAddAltName()(and before linking nodes in the other SAN cases) so the decode remains side-effect-free on failure.
wolfcrypt/src/asn.c:1 - The expression
(word32)strLen + idx - lenStartIdxis evaluated in 32-bit arithmetic and can overflow/wrap before the comparison, potentially allowing the bounds check to be bypassed for large values. To keep the check correct, compute the consumed length using a wider type (e.g., word64/size_t) or do overflow-safe incremental checks before comparing/subtracting fromlength.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
Fix confirmed by reporter |
dgarske
approved these changes
Mar 20, 2026
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
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.
Description
In
DecodeAltNames(), the non-template ASN path (--enable-asn=original) needs a bounds check beforelength -= strLen.Fixes zd21390
Testing
Added
test_DecodeAltNames_length_underflowChecklist