Skip to content

fix: resource leaks in _new_key_from_parameters() init on 3.x#138

Merged
atoomic merged 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-manifest-pss-test
Mar 24, 2026
Merged

fix: resource leaks in _new_key_from_parameters() init on 3.x#138
atoomic merged 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-manifest-pss-test

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented Mar 23, 2026

What

Fix resource leaks on error paths in _new_key_from_parameters() early initialization (OpenSSL 3.x), and add missing test file to MANIFEST.

Why

On OpenSSL 3.x, if EVP_PKEY_CTX_new_from_name(), EVP_PKEY_fromdata_init(), OSSL_PARAM_BLD_new(), or OSSL_PARAM_BLD_push_BN() failed during the early setup of _new_key_from_parameters(), the code used CHECK_OPEN_SSL() which croaks immediately — bypassing the err: cleanup label. This leaked pctx, params_build, and the input BIGNUMs.

How

  • Convert early CHECK_OPEN_SSL() to THROW()/goto err on the 3.x path, routing failures through the existing cleanup code
  • Initialize error = 0 at declaration (was uninitialized before the if(p||q) block)
  • Add t/pss_auto_promote.t to MANIFEST (missing since fix: PSS mgf1/saltlen setup for auto-promoted OAEP padding #133)

Testing

Full test suite passes (507 tests). The error paths are only reachable under extreme conditions (OOM, corrupted OpenSSL context) — the fix ensures they clean up properly instead of leaking.

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 7 insertions(+), 6 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

On OpenSSL 3.x, the early CHECK_OPEN_SSL() calls for pctx, params_build,
and push_BN operations would croak immediately on failure, bypassing the
err: cleanup label. This leaked pctx, params_build, and the input
BIGNUMs (n, e, d, p, q).

Convert to THROW()/goto err which routes through the existing cleanup
code. Also initialize `error` to 0 at declaration (was uninitialized
before the if(p||q) block).

Additionally adds t/pss_auto_promote.t to MANIFEST (missing since cpan-authors#133).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@timlegge timlegge left a comment

Choose a reason for hiding this comment

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

Reviewed- changes the immediate croak to instead cleanup and free memory as required before croaking.

Standard best practice in line with the design and tested with OpenSSL3 code path and earlier code path

@timlegge timlegge requested review from atoomic and toddr March 24, 2026 01:09
@atoomic atoomic marked this pull request as ready for review March 24, 2026 01:18
@atoomic atoomic merged commit 84225b7 into cpan-authors:main Mar 24, 2026
28 checks passed
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.

3 participants