fix: free BN_CTX and temp BIGNUMs on success path#112
Merged
atoomic merged 2 commits intocpan-authors:mainfrom Mar 19, 2026
Merged
Conversation
atoomic
approved these changes
Mar 17, 2026
atoomic
reviewed
Mar 17, 2026
Collaborator
|
@Koan-Bot rebase |
timlegge
requested changes
Mar 17, 2026
Member
timlegge
left a comment
There was a problem hiding this comment.
I think we should free dmp1, dmq1 and iqmp
| @@ -665,6 +665,12 @@ _new_key_from_parameters(proto, n, e, d, p, q) | |||
| #endif | |||
| #endif | |||
| dmp1 = dmq1 = iqmp = NULL; | |||
…ers() BN_CTX, p_minus_1, and q_minus_1 were only freed in the err: block, leaking on every successful key construction from parameters when p/q are provided. Also add missing THROW on q=BN_new() (potential NULL deref if malloc fails) and fix key_lifecycle.t test plan mismatch.
12bab70 to
7a10583
Compare
Contributor
Author
Rebase: fix: free BN_CTX and temp BIGNUMs on success pathBranch Diff: 1 file changed, 12 insertions(+), 1 deletion(-) Review feedback was analyzed and applied. Actions
CICI passed. Automated by Kōan |
timlegge
requested changes
Mar 18, 2026
Member
|
@atoomic fine to merge |
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.
What
Free BN_CTX, p_minus_1, and q_minus_1 on the success path in
_new_key_from_parameters(), and add missing THROW onq = BN_new().Why
These three allocations were only freed in the
err:block, meaning every successful call to_new_key_from_parameters()with p/q provided leaked a BN_CTX and two BIGNUMs. This affects all OpenSSL versions.The missing
THROW(q = BN_new())is inconsistent with thepcase (which has THROW) and would cause a NULL dereference in BN_div if malloc failed.Also fixes
key_lifecycle.ttest plan:skip()reports skipped tests which count toward the total, so the plan must always be 23 regardless of whether Bignum is available.Testing
All 244 tests pass on macOS with OpenSSL 3.6.1.
🤖 Generated with Claude Code