Explicit check for true instead of true-ish in OpenSSL::BN.rand
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby/openssl
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
ruby/openssl#1082 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
ruby/openssl#1075 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby/openssl#1038 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
ruby/openssl#988 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 45/100
ruby/openssl#975 · 3 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
darktable-org/darktable#22455 · 1 comment ·
Maintainers usually reply within 1 day
-
area:ci kind:gate-defect
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
InauguralSystems/EigenScript#1448 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
BasedHardware/omi#20084 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
raspberrypi/pico-sdk#3225 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100