Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#1,116 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, ruby
Domain
backend, security

Research direction

Read the OpenSSL::BN.rand implementation in ext/openssl/ossl_bn.c around the linked line, and check how it interprets the odd argument. The report suggests using Ruby's truthiness check; first confirm the intended behavior and whether compatibility requires documenting the existing behavior instead. Done means the behavior or its documentation is clarified and covered by an appropriate test.

Written by the indexing model from the issue text.

Description

This method has the following call sequence:

BN.rand(bits [, fill [, odd]]) -> aBN

If we look at the code at https://github.com/ruby/openssl/blob/ed948eae356b4226a10e59d772fdbbb845aecae2/ext/openssl/ossl_bn.c#L821

we see an explicit check for == Qtrue. This means passing any other value that is true-ish in Ruby is interpreted as false:

$ ruby -ropenssl -e 'p OpenSSL::BN.rand(8, 0, 1).to_i'
140
$ ruby -ropenssl -e 'p OpenSSL::BN.rand(8, 0, 1).to_i'
158

Here the first line generated an even number, even though we pass in a true-ish value.

bottom = RTEST(odd) ? 1 : 0;

I think this should be the preferred way.

If this is intentional (or should be kept to preserve behaviour), it should probably be reflected in the docs.

Dominant language
C
Stars
276
Forks
200
Avg merge
15h 35m
Merged PRs (30d)
7

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/openssl

All issues in ruby/openssl

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.