Skip to content

bn: treat any truthy odd argument to BN.rand as true - #1121

Merged
rhenium merged 1 commit into
ruby:masterfrom
CaptainAni187:bn-rand-truthy-odd
Oct 7, 2026
Merged

rhenium merged 1 commit into
ruby:masterfrom
CaptainAni187:bn-rand-truthy-odd

Conversation

@CaptainAni187

Copy link
Copy Markdown
Contributor

Fixes #1116

OpenSSL::BN.rand(bits, fill, odd) compared odd with Qtrue, so a truthy value other than true, such as 1, was ignored and the result could be even. It now uses RTEST(), as discussed in the issue.

test_random now also checks that BN.rand(8, 1, 1) is odd on each of its 10 draws. Without the change, that assertion fails. The test suite passes locally with OpenSSL 3.6.5 and Ruby 4.0.7.

OpenSSL::BN.rand compared the optional odd argument with Qtrue, so a
truthy value other than true, such as 1, was ignored and the result
could be even. Use RTEST() like other optional flags.

Fixes ruby#1116

@rhenium rhenium left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@rhenium
rhenium merged commit 3eacb0a into ruby:master Oct 7, 2026
48 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.

Explicit check for true instead of true-ish in OpenSSL::BN.rand

2 participants