1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[Win32] Negative length IO#sysread

Raise `ArgumentError` in `IO#sysread` on Windows when given a negative
length.

Fixes [Bug #18880]
This commit is contained in:
Jeremy Bopp 2022-09-11 09:08:14 -05:00 committed by GitHub
parent 472e7b8518
commit 684353fc03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2022-09-11 23:08:39 +09:00
Merged: https://github.com/ruby/ruby/pull/6354

Merged-By: nobu <nobu@ruby-lang.org>
2 changed files with 10 additions and 1 deletions

3
io.c
View file

@ -3053,7 +3053,8 @@ static int
io_setstrbuf(VALUE *str, long len)
{
#ifdef _WIN32
len = (len + 1) & ~1L; /* round up for wide char */
if (len > 0)
len = (len + 1) & ~1L; /* round up for wide char */
#endif
if (NIL_P(*str)) {
*str = rb_str_new(0, len);

View file

@ -2213,6 +2213,14 @@ class TestIO < Test::Unit::TestCase
end)
end
def test_sysread_with_negative_length
make_tempfile {|t|
open(t.path) do |f|
assert_raise(ArgumentError) { f.sysread(-1) }
end
}
end
def test_flag
make_tempfile {|t|
assert_raise(ArgumentError) do