Check BN_new() and RSA_new() return values in generate_key()#184
Draft
toddr-bot wants to merge 1 commit into
Draft
Check BN_new() and RSA_new() return values in generate_key()#184toddr-bot wants to merge 1 commit into
toddr-bot wants to merge 1 commit into
Conversation
BN_new() can return NULL on memory exhaustion. The subsequent BN_set_word(e, exponent) would dereference NULL — a segfault instead of a clean error. Similarly, on OpenSSL 0.9.8–2.x, RSA_new() was unchecked; failure would pass NULL to RSA_generate_key_ex(). Add CHECK_OPEN_SSL(e) after BN_new(), and an explicit NULL check with cleanup for RSA_new() in the 0.9.8–2.x code path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
BN_new()— prevents segfault on memory exhaustionRSA_new()in the 0.9.8–2.x code path with proper cleanupWhy
BN_new()returns NULL on allocation failure. Without a check,BN_set_word(NULL, exponent)dereferences a null pointer — a segfaultinstead of a clean croak. Similarly, in the 0.9.8–2.x path,
RSA_new()failure would pass NULL toRSA_generate_key_ex().Every other allocation in RSA.xs is checked (
CHECK_OPEN_SSL,THROW,or explicit
if). These two were the last unchecked allocations ingenerate_key().Testing
straightforward: add checks that match the existing patterns
🤖 Generated with Claude Code