Skip to content

Fix wolfSSL_d2i_X509_fp's handling of multiple certs in a single DER. - #12160

Open
kareem-wolfssl wants to merge 3 commits into
wolfSSL:masterfrom
kareem-wolfssl:zd22757_2
Open

kareem-wolfssl wants to merge 3 commits into
wolfSSL:masterfrom
kareem-wolfssl:zd22757_2

Conversation

@kareem-wolfssl

Copy link
Copy Markdown
Contributor

Description

Fixes zd#22757

Testing

Provided reproducer, added test

Checklist

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

@kareem-wolfssl
kareem-wolfssl requested a balanced review from Copilot November 17, 2026 18:32
@kareem-wolfssl kareem-wolfssl self-assigned this Nov 17, 2026
@kareem-wolfssl

Copy link
Copy Markdown
Contributor Author

@claude review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the change supporting sequential reads of concatenated DER certificates.

No open issues 🎉

What changed in this PR

Fixes wolfSSL_d2i_X509_fp so callers can read concatenated DER certificates one at a time, preserving the file position for subsequent reads.

Changes:

  • Reads from the current file position and advances past only the decoded certificate.
  • Adds and registers regression coverage for sequential certificate reads through both file and BIO APIs, including end-of-file handling.
File Description
tests/​api/​test_ossl_x509_io.h Declares and registers the concatenated-certificate regression test.
tests/​api/​test_ossl_x509_io.c Tests sequential file and BIO reads, certificate contents, and end-of-file behavior.
src/​x509.c Updates file decoding to consume one certificate from the current position.

Review effort: Balanced

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline finding, I also checked whether removing the explicit size check from wolfSSL_d2i_X509_fp_ex loosened anything. It didn't: wolfssl_file_len still rejects sizes above MAX_WOLFSSL_FILE_SIZE and sizes of 0 or less (src/ssl_misc.c:265). I also checked whether start can be used before it is set. It can't: when wolfssl_file_len fails, sz stays 0 and the function returns before the seek.

Extended reasoning...

The change makes wolfSSL_d2i_X509_fp_ex (src/x509.c) read from the file's current position and decode only one certificate per call, using wolfssl_file_len from ssl_misc.c. That file is #included into ssl.c before x509.c, so x509.c can see the static helper.

Comment thread src/x509.c Resolved
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.

2 participants