Skip to content

Fix the error handling on wc_PKCS7_DecodeAuthEnvelopedData#10629

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_4637
Open

Fix the error handling on wc_PKCS7_DecodeAuthEnvelopedData#10629
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_4637

Conversation

@yosuke-wolfssl
Copy link
Copy Markdown
Contributor

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

  • wolfcrypt/src/pkcs7.c compiles clean (--enable-all config).
  • Full library + tests build clean.
  • testwolfcrypt passes (exit 0); PKCS7authenveloped test passed! confirms no regression on the success path.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Jun 8, 2026
Copilot AI review requested due to automatic review settings June 8, 2026 01:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()+return in WC_PKCS7_AUTHENV_6 with break so 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.

Comment thread wolfcrypt/src/pkcs7.c
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #10629

Scan targets checked: none
Failed targets: wolfcrypt-bugs, wolfcrypt-src

⚠️ Review incomplete — one or more scan targets failed before findings could be produced. See the Fenrir PR review detail page for logs.

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.

4 participants