Skip to content

Fix FillSigner to clear pubkeystored#10033

Open
embhorn wants to merge 2 commits intowolfSSL:masterfrom
embhorn:gh10028
Open

Fix FillSigner to clear pubkeystored#10033
embhorn wants to merge 2 commits intowolfSSL:masterfrom
embhorn:gh10028

Conversation

@embhorn
Copy link
Member

@embhorn embhorn commented Mar 20, 2026

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_test

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@embhorn embhorn self-assigned this Mar 20, 2026
Copilot AI review requested due to automatic review settings March 20, 2026 19:20
Copy link
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

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->pubKeyStored and cert->subjectCNStored after ownership transfer in FillSigner().
  • Expose a small set of ASN/signer helpers with test visibility so they can be invoked from the test suite.
  • Add fill_signer_twice_test regression 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

  • cert is a stack variable that is not initialized before potential ERROR_OUT(..., done) jumps (e.g., file open/read failures). Calling FreeDecodedCert(&cert) on an uninitialized DecodedCert can invoke frees on garbage pointers. Fix by zero-initializing cert at declaration (e.g., XMEMSET(&cert, 0, sizeof(cert));) or tracking whether InitDecodedCert() has been called and only calling FreeDecodedCert() 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_BUF and 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_BUF and not EOF) and fail with a clear error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

[Bug]: cert->pubkeystored is never cleared even when the public key is

2 participants