Permalink
Browse files

Read length after args in String#setbyte

Prevents RCE
Reported by https://hackerone.com/raydot
  • Loading branch information...
Craig Lehmann authored and bouk committed Nov 15, 2016
1 parent a630c4f commit 83005d83d8ba95524436409d5d73fd82b63bc115
Showing with 14 additions and 1 deletion.
  1. +2 −1 mrbgems/mruby-string-ext/src/string.c
  2. +12 −0 mrbgems/mruby-string-ext/test/string.rb
@@ -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_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))

0 comments on commit 83005d8

Please sign in to comment.