mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Read length after args in String#setbyte
Prevents RCE Reported by https://hackerone.com/raydot
This commit is contained in:
committed by
Bouke van der Bijl
parent
a630c4f413
commit
83005d83d8
@@ -23,10 +23,11 @@ static mrb_value
|
||||
mrb_str_setbyte(mrb_state *mrb, mrb_value str)
|
||||
{
|
||||
mrb_int pos, byte;
|
||||
long len = RSTRING_LEN(str);
|
||||
long len;
|
||||
|
||||
mrb_get_args(mrb, "ii", &pos, &byte);
|
||||
|
||||
len = RSTRING_LEN(str);
|
||||
if (pos < -len || len <= pos)
|
||||
mrb_raisef(mrb, E_INDEX_ERROR, "index %S is out of array", mrb_fixnum_value(pos));
|
||||
if (pos < 0)
|
||||
|
||||
@@ -30,6 +30,18 @@ assert('String#setbyte') do
|
||||
assert_equal("Hello", str1)
|
||||
end
|
||||
|
||||
assert("String#setbyte raises IndexError if arg conversion resizes String") do
|
||||
$s = "01234\n"
|
||||
class Tmp
|
||||
def to_i
|
||||
$s.chomp! ''
|
||||
95
|
||||
end
|
||||
end
|
||||
tmp = Tmp.new
|
||||
assert_raise(IndexError) { $s.setbyte(5, tmp) }
|
||||
end
|
||||
|
||||
assert('String#byteslice') do
|
||||
str1 = "hello"
|
||||
assert_equal("e", str1.byteslice(1))
|
||||
|
||||
Reference in New Issue
Block a user