Fix segfault on remove_method with invalid argument

Reported by https://hackerone.com/jpenalbae
parent a630c4f4
...@@ -2068,7 +2068,7 @@ mrb_mod_remove_method(mrb_state *mrb, mrb_value mod) ...@@ -2068,7 +2068,7 @@ mrb_mod_remove_method(mrb_state *mrb, mrb_value mod)
mrb_get_args(mrb, "*", &argv, &argc); mrb_get_args(mrb, "*", &argv, &argc);
while (argc--) { while (argc--) {
remove_method(mrb, mod, mrb_symbol(*argv)); remove_method(mrb, mod, to_sym(mrb, *argv));
argv++; argv++;
} }
return mod; return mod;
......
...@@ -401,3 +401,12 @@ assert('class with non-class/module outer raises TypeError') do ...@@ -401,3 +401,12 @@ assert('class with non-class/module outer raises TypeError') do
assert_raise(TypeError) { class 0::C1; end } assert_raise(TypeError) { class 0::C1; end }
assert_raise(TypeError) { class []::C2; end } assert_raise(TypeError) { class []::C2; end }
end end
assert("remove_method doesn't segfault if the passed in argument isn't a symbol") do
klass = Class.new
assert_raise(TypeError) { klass.remove_method nil }
assert_raise(TypeError) { klass.remove_method 123 }
assert_raise(TypeError) { klass.remove_method 1.23 }
assert_raise(NameError) { klass.remove_method "hello" }
assert_raise(TypeError) { klass.remove_method Class.new }
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment