Fix the error handling on wc_PKCS7_DecodeAuthEnvelopedData#10629
Open
yosuke-wolfssl wants to merge 1 commit into
Open
Fix the error handling on wc_PKCS7_DecodeAuthEnvelopedData#10629yosuke-wolfssl wants to merge 1 commit into
yosuke-wolfssl wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a streaming error-handling bug in wc_PKCS7_DecodeAuthEnvelopedData() (AuthEnvelopedData decode) where an AES-GCM/CCM authentication-tag failure could free encryptedContent and return early, leaving streaming state/pointers inconsistent and risking use-after-free/double-free on re-entry.
Changes:
- Replace an early
XFREE()+returninWC_PKCS7_AUTHENV_6withbreakso execution reaches the existing shared cleanup path. - Add an explanatory comment documenting why falling through to the shared error handler is required for stream safety.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10629
Scan targets checked: none
Failed targets: wolfcrypt-bugs, wolfcrypt-src
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 the streaming path of wc_PKCS7_DecodeAuthEnvelopedData, state WC_PKCS7_AUTHENV_6 XFREEs encryptedContent on AES-GCM/CCM authentication tag failure then returns immediately without nulling pkcs7->stream->bufferPt and without calling wc_PKCS7_ResetStream. pkcs7->state remains WC_PKCS7_AUTHENV_6.
Addressed by f_4637.
Changes
Replaced it with a break (plus a comment) so control falls through to the existing shared error handler that already ForceZeros + frees encryptedContent, nulls bufferPt/key, and calls wc_PKCS7_ResetStream. This matches the other error breaks in the same switch and avoids the double-free that inlining the cleanup would have caused.
Testing