asn: check CALLOC_ASNGETDATA result before use in DecodeCertInternal - #11378
Merged
Frauschi merged 1 commit intoSep 4, 2026
Merged
Conversation
Under WOLFSSL_SMALL_STACK the macro heap-allocates and reports failure through its err argument, but RPKdataASN was indexed before ret was tested, so an allocation failure dereferenced NULL while parsing any certificate. The MEMORY_E was also discarded, since the following GetASN_Items overwrote ret. Audited the other 57 ALLOC_ASNGETDATA/CALLOC_ASNGETDATA call sites; this was the only unguarded one.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, fixes a clear NULL-dereference bug, and preserves the existing control flow for successful allocations/parsing.
Pull request overview
Fixes a crash path in certificate decoding when WOLFSSL_SMALL_STACK is enabled by ensuring CALLOC_ASNGETDATA() allocation success is checked before indexing into RPKdataASN during Raw Public Key (RPK) parsing in DecodeCertInternal().
Changes:
- Guard
GetASN_OID()/GetASN_Items()calls behindif (ret == 0)afterCALLOC_ASNGETDATA()for RPK parsing. - Prevent potential NULL dereference on allocation failure while parsing certificates with
HAVE_RPK.
File summaries
| File | Description |
|---|---|
| wolfcrypt/src/asn.c | Adds a ret == 0 guard before indexing/using RPKdataASN after CALLOC_ASNGETDATA() in DecodeCertInternal() to avoid NULL dereference on allocation failure. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Frauschi
approved these changes
Sep 4, 2026
Member
Author
|
retest this please |
douzzer
approved these changes
Sep 4, 2026
Contributor
|
Retest this please. (scripts/external.test in generic config PRB) edit: known issue, to be resolved by: |
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
When WOLFSSL_SMALL_STACK is enabled, the macro allocates and may report failure through its err argument, but RPKdataASN is indexed before ret is checked, so an allocation failure dereferences NULL while parsing any certificate and discards the MEMORY_E.
Testing
Discovered (and now covered) during MC/DC part 8 campaign #11355 - Regression tests being added there.