Skip to content

fix: generate_key() BIGNUM leak on OpenSSL 3.x#78

Merged
atoomic merged 1 commit intocpan-authors:mainfrom
atoomic:koan.atoomic/fix-generate-key-bn-leak
Mar 12, 2026
Merged

fix: generate_key() BIGNUM leak on OpenSSL 3.x#78
atoomic merged 1 commit intocpan-authors:mainfrom
atoomic:koan.atoomic/fix-generate-key-bn-leak

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

Summary

  • The exponent BIGNUM e was set to NULL before calling BN_free(), making the free a no-op
  • EVP_PKEY_CTX_set1_rsa_keygen_pubexp() uses set1 semantics (copies the value), so the caller retains ownership and must free the original
  • Removed the dead e = NULL line so BN_free(e) actually frees the BIGNUM

Impact

Memory leak of one BIGNUM on every generate_key() call when built against OpenSSL >= 3.0.

Test plan

  • All 278 existing tests pass
  • generate_key() tested in rsa.t (512-bit and 2048-bit)

🤖 Generated with Claude Code

@atoomic atoomic marked this pull request as ready for review February 20, 2026 02:29
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.

LGTM - I might add a

if (e != NULL)

before the BN_free() but otherwise LGTM

@Koan-Bot Koan-Bot force-pushed the koan.atoomic/fix-generate-key-bn-leak branch from 7d8f14f to 75fef76 Compare February 25, 2026 06:08
Koan-Bot added a commit to atoomic/Crypt-OpenSSL-RSA that referenced this pull request Feb 25, 2026
@Koan-Bot
Copy link
Copy Markdown
Contributor Author

Rebase: fix: generate_key() BIGNUM leak on OpenSSL 3.x

Branch koan.atoomic/fix-generate-key-bn-leak has been rebased onto main and force-pushed.

Actions

  • Read PR comments and review feedback
  • Rebased koan.atoomic/fix-generate-key-bn-leak onto upstream/main
  • Applied review feedback
  • Force-pushed koan.atoomic/fix-generate-key-bn-leak to origin

Automated by Kōan

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.

Looks fine to me

@Koan-Bot
Copy link
Copy Markdown
Contributor Author

Rebase: fix: generate_key() BIGNUM leak on OpenSSL 3.x

Branch koan.atoomic/fix-generate-key-bn-leak rebased onto main and force-pushed.

Diff: 1 file changed, 2 insertions(+), 1 deletion(-)

Review feedback was analyzed and applied.

Actions

  • Rebased koan.atoomic/fix-generate-key-bn-leak onto upstream/main
  • Force-pushed koan.atoomic/fix-generate-key-bn-leak to origin

Automated by Kōan

@Koan-Bot Koan-Bot force-pushed the koan.atoomic/fix-generate-key-bn-leak branch from 75fef76 to 67f8d45 Compare March 12, 2026 02:19
@atoomic atoomic merged commit 078da52 into cpan-authors:main Mar 12, 2026
25 checks passed
Koan-Bot added a commit to atoomic/Crypt-OpenSSL-RSA that referenced this pull request Mar 15, 2026
Koan-Bot added a commit to atoomic/Crypt-OpenSSL-RSA that referenced this pull request Mar 15, 2026
Koan-Bot added a commit to atoomic/Crypt-OpenSSL-RSA that referenced this pull request Mar 15, 2026
Koan-Bot added a commit to atoomic/Crypt-OpenSSL-RSA that referenced this pull request Mar 16, 2026
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