Skip to content

Commit

Permalink
Use mrb_ptr instead of mrb_cptr in Kernel#to_s
Browse files Browse the repository at this point in the history
This is to avoid segfault when WORD_BOXING is enabled

Reported by https://hackerone.com/brakhane
  • Loading branch information
bouk committed Dec 1, 2016
1 parent 2cca9d3 commit 9c61e1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions test/t/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9c61e1c

Please sign in to comment.