fix: verify() error-path resource leaks on OpenSSL 3.x#102
Conversation
PR Review — fix: verify() error-path resource leaks on OpenSSL 3.xThe PR correctly identifies and fixes error-path leaks where THROW/goto-err replaces CHECK_OPEN_SSL, but it misses the success-path leak which is far more impactful — 🔴 Blocking1. Success-path leak: ctx and md never freed when verify succeeds ( The error path cleanup is correct, but the success path needs explicit cleanup before the switch. Add frees between verify_result = EVP_PKEY_verify(ctx, sig, sig_length, digest, get_digest_length(p_rsa->hashMode));
EVP_MD_free(md);
EVP_PKEY_CTX_free(ctx);Note: the version currently on 🟡 Important1. goto verify_done is dead code ( Checklist
SummaryThe PR correctly identifies and fixes error-path leaks where THROW/goto-err replaces CHECK_OPEN_SSL, but it misses the success-path leak which is far more impactful — Automated review by Kōan |
|
@toddr @toddr-bot Please rebase. Some of the other PRs have been merged |
|
❌ Unknown command
Usage: |
|
@toddr-bot rebase |
Rebase: fix: verify() error-path resource leaks on OpenSSL 3.xBranch Review feedback was analyzed and applied. Actions
Automated by Kōan |
95cecde to
a2db97c
Compare
What
Fix EVP_PKEY_CTX and EVP_MD leaks in
verify()when OpenSSL 3.x setup calls fail.Why
The
CHECK_OPEN_SSLmacro croaks immediately on failure. Inverify()'s setup path (lines 1116-1130), ifEVP_PKEY_verify_init,EVP_PKEY_CTX_set_rsa_padding, orEVP_PKEY_CTX_set_signature_mdfails, the already-allocatedctxandmdare never freed.This completes the CHECK_OPEN_SSL → THROW cleanup campaign across all OpenSSL 3.x code paths in RSA.xs.
How
Replace
CHECK_OPEN_SSLwithTHROWfor the setup calls, and add anerr:label that frees both resources before croaking. BothEVP_PKEY_CTX_free(NULL)andEVP_MD_free(NULL)are documented no-ops, so the cleanup is safe regardless of which step fails.Testing
All 318 tests pass. The normal verify path is unchanged — only the error-path cleanup is new.
Quality Report
Changes: 1 file changed, 20 insertions(+), 12 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline