Skip to content

asn: check CALLOC_ASNGETDATA result before use in DecodeCertInternal - #11378

Merged
Frauschi merged 1 commit into
wolfSSL:masterfrom
danielinux:asn-parse-fix-alloc-fails-handling
Sep 4, 2026
Merged

asn: check CALLOC_ASNGETDATA result before use in DecodeCertInternal#11378
Frauschi merged 1 commit into
wolfSSL:masterfrom
danielinux:asn-parse-fix-alloc-fails-handling

Conversation

@danielinux

Copy link
Copy Markdown
Member

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.

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.
Copilot AI lite review requested due to automatic review settings September 4, 2026 12:21

Copilot AI 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.

🟢 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 behind if (ret == 0) after CALLOC_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.

@danielinux danielinux self-assigned this Sep 4, 2026
@danielinux

Copy link
Copy Markdown
Member Author

retest this please
(unrelated failure)

@philljj

philljj commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

(scripts/external.test in generic config PRB)

edit: known issue, to be resolved by:

@Frauschi
Frauschi merged commit 6bbd236 into wolfSSL:master Sep 4, 2026
385 of 386 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants