fix: prevent resource leaks in generate_key() and get_public_key_string()#101
Conversation
|
@Koan-Bot review |
PR Review — fix: prevent resource leaks in generate_key() and get_public_key_string()Solid, focused fix that correctly addresses resource leaks on error paths in both 🟢 Suggestions1. Redundant NULL check after successful RSA_generate_key_ex ( 2. Inconsistent indentation in error block ( Checklist
SummarySolid, focused fix that correctly addresses resource leaks on error paths in both Automated review by Kōan |
|
Would be nice to add some unit test to cover the fix we are adding there. |
|
@toddr-bot rebase |
…ng() generate_key() leaked the BIGNUM exponent (e) and EVP_PKEY_CTX on all OpenSSL version paths when error-path croaks fired before cleanup: - Pre-0.00908: e was never freed - 1.1.x: e and rsa leaked when RSA_generate_key_ex() failed - 3.x: CHECK_OPEN_SSL croaks bypassed BN_free(e) and EVP_PKEY_CTX_free(ctx) Replace CHECK_OPEN_SSL chain with short-circuit conditional that frees all resources before calling croakSsl(). For 1.1.x, free e and rsa before croak() on key generation failure. get_public_key_string() leaked the OSSL_ENCODER_CTX and BIO when the second CHECK_OPEN_SSL croak fired after encoder context allocation. Replace with short-circuit conditional for consistent cleanup.
Rebase: fix: prevent resource leaks in generate_key() and get_public_key_string()Branch Diff: 1 file changed, 24 insertions(+), 13 deletions(-) Review feedback was analyzed and applied. Actions
Automated by Kōan |
4e485be to
5ae2ee7
Compare
|
@toddr-bot rebase can we add some unit tests to cover the update |
timlegge
left a comment
There was a problem hiding this comment.
looks fine. I was a little worried about the order of operations for the funca() || funcb() but I understand that it is guaranteed left to right so looks fine
Rebase: fix: prevent resource leaks in generate_key() and get_public_key_string()Branch Review feedback was analyzed and applied. Actions
CICI passed. Automated by Kōan |
What
Fix resource leaks on error paths in
generate_key()(all OpenSSL versions) andget_public_key_string()(OpenSSL 3.x).Why
CHECK_OPEN_SSLis a croak macro — when it fires, any resources allocated before it are leaked. Ingenerate_key(), the BIGNUM exponenteis allocated at function entry but only freed on the success path. On OpenSSL 3.x, theEVP_PKEY_CTXalso leaks. Similarly,get_public_key_string()leaks theOSSL_ENCODER_CTXandBIOwhen encoding fails.How
Replace
CHECK_OPEN_SSLchains with short-circuit conditionals (if (!a || !b || ...)) that test all operations, then free resources before callingcroakSsl(). This is the same pattern used inrsa_crypt()(PR #100). For the OpenSSL 1.1.x path ingenerate_key(), freeeandrsabeforecroak().Testing
Full test suite passes (318 tests across 10 files).
🤖 Generated with Claude Code
Quality Report
Changes: 1 file changed, 24 insertions(+), 11 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline