Fix FillSigner to clear pubkeystored#10033
Open
embhorn wants to merge 2 commits intowolfSSL:masterfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a FillSigner() ownership-transfer edge case by clearing DecodedCert “stored” flags after transferring pointers to a Signer, and adds a regression test to ensure repeated FillSigner() calls on the same DecodedCert don’t propagate stale NULL pointers.
Changes:
- Clear
cert->pubKeyStoredandcert->subjectCNStoredafter ownership transfer inFillSigner(). - Expose a small set of ASN/signer helpers with test visibility so they can be invoked from the test suite.
- Add
fill_signer_twice_testregression test and wire it into the cert test flow.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| wolfssl/wolfcrypt/asn.h | Adjusts visibility/macros for FillSigner/signer helpers and DER alloc/free so tests can call them. |
| wolfcrypt/src/asn.c | Clears pubKeyStored and subjectCNStored when FillSigner() transfers ownership. |
| wolfcrypt/test/test.c | Adds and runs a regression test that calls FillSigner() twice on the same DecodedCert. |
Comments suppressed due to low confidence (3)
wolfcrypt/test/test.c:1
certis a stack variable that is not initialized before potentialERROR_OUT(..., done)jumps (e.g., file open/read failures). CallingFreeDecodedCert(&cert)on an uninitializedDecodedCertcan invoke frees on garbage pointers. Fix by zero-initializingcertat declaration (e.g.,XMEMSET(&cert, 0, sizeof(cert));) or tracking whetherInitDecodedCert()has been called and only callingFreeDecodedCert()when initialized.
wolfcrypt/test/test.c:1- The test silently truncates the cert if the file is larger than
FOURK_BUF(e.g.,bytes == FOURK_BUF), which makes the test brittle and can cause confusing parse failures when test certs change. Consider sizing the buffer to the file length (seek/tell + allocate), or at least detect truncation (bytes == FOURK_BUFand not EOF) and fail with a clear error.
wolfcrypt/test/test.c:1 - The test silently truncates the cert if the file is larger than
FOURK_BUF(e.g.,bytes == FOURK_BUF), which makes the test brittle and can cause confusing parse failures when test certs change. Consider sizing the buffer to the file length (seek/tell + allocate), or at least detect truncation (bytes == FOURK_BUFand not EOF) and fail with a clear error.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Added cert->pubKeyStored = 0 and cert->subjectCNStored = 0 after the pointers are transferred to the signer, so subsequent calls to FillSigner on the same DecodedCert won't copy stale NULL pointers.
Fixes #10028
Testing
Added
fill_signer_twice_testChecklist