Fix cert chain size issue#9827
Merged
JacobBarthelmeh merged 3 commits intowolfSSL:masterfrom Feb 25, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a potential 32-bit integer overflow when extending a certificate chain in wolfssl_add_to_chain, and adds a regression test to ensure the overflow is rejected.
Changes:
- Add an overflow guard for
len + CERT_HEADER_SZ + certSzinwolfssl_add_to_chain - Add an API test that simulates a near-
UINT32_MAXchain length to verify failure behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/api.c | Adds a regression test that forces the size calculation into an overflow scenario. |
| src/ssl_load.c | Adds bounds checks to prevent word32 overflow when computing the new chain allocation size. |
Comments suppressed due to low confidence (1)
tests/api.c:1
- This test replaces
ctx->certChainwith aDerBufferthat doesn't appear to follow the same allocation/free pattern as production code (e.g.,AllocDercommonly allocatesDerBufferandbufferin a specific way). Also, freeing the existing chain withXFREE(ctx->certChain, ...)may bypass any required freeing ofctx->certChain->buffer(depending on howDerBufferinstances are normally allocated). To make this test robust and avoid allocator/cleanup fragility, construct the fake chain using the same helper(s) used by production (e.g., anAllocDer-style path) and dispose of the original chain using the correspondingDerBufferfree routine (or explicitly free bothbufferand the struct in the same way production does).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
tests/api.c:1
ctx->heapis dereferenced unconditionally when allocatingfakeChain. IfwolfSSL_CTX_new(...)fails,ExpectNotNulllikely records the failure but execution continues, leading to a null dereference here. Wrap the remainder of the test body in anif (EXPECT_SUCCESS()) { ... }block (or return early) before usingctx/ctx->heap.
tests/api.c:1ctx->certChainis aDerBuffer*and is typically created/freed via the DER buffer helpers (e.g.,AllocDer+ the matching free routine). Freeing it withXFREErisks leaking the embeddedbufferor freeing with the wrong routine (depending on how the chain was allocated). Prefer using the same deallocation function used elsewhere forDerBufferinstances (the one that also releasescertChain->buffer).
tests/api.c:1fakeChain->bufferis pointed inside the same allocation as the struct. When the context is freed, the cleanup path for aDerBuffercommonly freesbufferseparately from the struct; if that happens, this setup can trigger an invalid free / heap corruption. To keep the test safe, constructfakeChainin a way that matches the normalDerBufferownership model (e.g., allocatebufferindependently, or use the standard DER allocation helper and then adjust the length for the overflow scenario).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
Jenkins retest this please |
1 similar comment
Member
Author
|
Jenkins retest this please |
JacobBarthelmeh
approved these changes
Feb 25, 2026
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
wolfssl_add_to_chain, the calculation len + CERT_HEADER_SZ + certSz uses word32, which could cause an overflowFixes zd21241
Testing
Added test case
test_wolfSSL_add_to_chain_overflowChecklist