Permalink
Browse files

Use mrb_ptr instead of mrb_cptr in Kernel#to_s

This is to avoid segfault when WORD_BOXING is enabled

Reported by https://hackerone.com/brakhane
  • Loading branch information...
bouk committed Nov 28, 2016
1 parent 2cca9d3 commit 9c61e1cd87aca3646fe39a6d53223efdcb11e250
Showing with 16 additions and 1 deletion.
  1. +1 −1 src/object.c
  2. +15 −0 test/t/kernel.rb
View
@@ -444,7 +444,7 @@ mrb_any_to_s(mrb_state *mrb, mrb_value obj)
mrb_str_cat_lit(mrb, str, "#<");
mrb_str_cat_cstr(mrb, str, cname);
mrb_str_cat_lit(mrb, str, ":");
mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, mrb_cptr(obj)));
mrb_str_concat(mrb, str, mrb_ptr_to_str(mrb, mrb_ptr(obj)));
mrb_str_cat_lit(mrb, str, ">");
return str;
View
@@ -520,6 +520,21 @@ def test_method; end
assert_equal to_s.class, String
end
assert('Kernel#to_s on primitives') do
begin
Fixnum.alias_method :to_s_, :to_s
Fixnum.remove_method :to_s
assert_nothing_raised do
# segfaults if mrb_cptr is used
1.to_s
end
ensure
Fixnum.alias_method :to_s, :to_s_
Fixnum.remove_method :to_s_
end
end
assert('Kernel.local_variables', '15.3.1.2.7') do
a, b = 0, 1
a += b

0 comments on commit 9c61e1c

Please sign in to comment.