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:
parent
472e7b8518
commit
684353fc03
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
1
io.c
1
io.c
|
@ -3053,6 +3053,7 @@ static int
|
||||||
io_setstrbuf(VALUE *str, long len)
|
io_setstrbuf(VALUE *str, long len)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
if (len > 0)
|
||||||
len = (len + 1) & ~1L; /* round up for wide char */
|
len = (len + 1) & ~1L; /* round up for wide char */
|
||||||
#endif
|
#endif
|
||||||
if (NIL_P(*str)) {
|
if (NIL_P(*str)) {
|
||||||
|
|
|
@ -2213,6 +2213,14 @@ class TestIO < Test::Unit::TestCase
|
||||||
end)
|
end)
|
||||||
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
|
def test_flag
|
||||||
make_tempfile {|t|
|
make_tempfile {|t|
|
||||||
assert_raise(ArgumentError) do
|
assert_raise(ArgumentError) do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue