asn: fix coverity null deref warnings.#9960
Merged
dgarske merged 1 commit intowolfSSL:masterfrom Mar 13, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Resolves Coverity-reported null dereference warnings in wolfcrypt/src/asn.c by preventing macro argument evaluation when key pointers are invalid and making cleanup paths safer.
Changes:
- Guard
ALLOC_ASNGETDATA/CALLOC_ASNGETDATAinvocations behindret == 0to avoid dereferencingkey->heapwhenkeyis invalid. - Make
FREE_ASNSETDATAcleanup resilient tokey == NULLusing a conditional heap argument.
Comments suppressed due to low confidence (4)
wolfcrypt/src/asn.c:1
- Optional: instead of introducing an extra
if (ret == 0)block solely to avoid evaluatingkey->heap, consider passing a safely-evaluated heap expression into the macro (e.g.,key ? key->heap : NULL). This keeps control flow flatter and relies on the existingret-based gating inside the macro (if present), while still preventing null deref from macro argument evaluation.
wolfcrypt/src/asn.c:1 - Optional: same pattern as earlier—if the only reason for the
if (ret == 0)wrapper is to avoid evaluatingkey->heapin macro arguments, a conditional heap expression argument can avoid added nesting while still being null-safe.
wolfcrypt/src/asn.c:1 - Please confirm
FREE_ASNSETDATAis defined to safely accept aNULLheap and still free using the correct allocator. If the heap parameter controls which allocator is used, passingNULLcould risk mismatched free behavior. A more robust approach is to capture the heap used for allocation into a local variable (or only call the free macro when the allocator context is known) and use that consistently during cleanup.
wolfcrypt/src/asn.c:1 - Same concern as the earlier
FREE_ASNSETDATAchange: if heap selects the allocator, ensureNULLis a supported value that won’t cause allocator mismatch. Consider retaining the allocation heap in a local variable for consistent cleanup.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
JacobBarthelmeh
approved these changes
Mar 12, 2026
Contributor
Author
|
Retest this please. |
dgarske
approved these changes
Mar 13, 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
Fix coverity issues in wolfcrypt/src/asn.c.