Repository navigation
ssl: raise ArgumentError for a negative length in SSLSocket#sysread - #1123
Merged
Merged
Conversation
Shaisolaris
force-pushed
the
sysread-negative-length
branch
from
October 16, 2026 13:16
2de20a6 to
6499911
Compare
Member
|
We should make (As a bonus - The second commit doesn't look necessary. |
rhenium
force-pushed
the
sysread-negative-length
branch
from
October 16, 2026 16:21
6499911 to
bafa498
Compare
Member
|
windows mingw head looks outdated: Ruby < 3.2 on Windows appears to be failing due to https://bugs.ruby-lang.org/issues/18880 |
rhenium
force-pushed
the
sysread-negative-length
branch
from
October 16, 2026 16:37
bafa498 to
087ef40
Compare
Check the length so that #sysread, #read_nonblock and the buffer variants raise ArgumentError. Co-authored-by: Kazuki Yamaguchi <k@rhe.jp>
rhenium
force-pushed
the
sysread-negative-length
branch
from
October 16, 2026 16:50
087ef40 to
9443e67
Compare
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.
Since bf1a419 ("ssl: implement blocking SSLSocket methods in Ruby"), a negative length passed to
SSLSocket#sysreador#read_nonblockreachesSSL_read():The new
string_new_capacityclamps the capacity to 0, so the oldArgumentErrorfromrb_str_new()no longer happens. With a caller-provided buffer the negative length already reachedSSL_read()before that commit.This adds a check in
ssl_readthat raisesArgumentErrorfor a negative length, likeIO#sysread, in all of these paths. The change has not been released yet (it is not in v4.0.2).Tests:
test_sysread_negative_lengthtotest/openssl/test_pair.rb. It fails on master and passes with this change.test_pair.rb(33 tests),test_ssl.rb(92),test_ssl_session.rb(11) andtest_buffering.rb(5) pass locally on Ruby 3.3.8 with the system OpenSSL. I did not run the fullrake testor the CI matrix of OpenSSL/LibreSSL/AWS-LC versions.Follow-up validation — October 16
Follow-up validation (October 16): independently detect rb_len2long rather than assuming that HAVE_RB_LEN_T implies the conversion helper exists. A syntax-only compile probe with a present length type and absent helper fails before and passes after the guard repair. The negative-length regression now lives in the SSL test class rather than the shared native Socket mixin. Built on Ruby 3.4.8/OpenSSL 3.6.2; full socket-pair file: 103 tests, 531 assertions, no failures. Windows/Ruby-head CI remains to be verified.