Permalink
Browse files

Fix segfault on remove_method with invalid argument

  • Loading branch information...
bouk committed Nov 14, 2016
1 parent a630c4f commit 22f550405449faf5bb424f04a52835376add2ae2
Showing with 10 additions and 1 deletion.
  1. +1 −1 src/class.c
  2. +9 −0 test/t/class.rb
View
@@ -2068,7 +2068,7 @@ mrb_mod_remove_method(mrb_state *mrb, mrb_value mod)
mrb_get_args(mrb, "*", &argv, &argc);
while (argc--) {
remove_method(mrb, mod, mrb_symbol(*argv));
remove_method(mrb, mod, to_sym(mrb, *argv));
argv++;
}
return mod;
View
@@ -401,3 +401,12 @@ def class_variable
assert_raise(TypeError) { class 0::C1; end }
assert_raise(TypeError) { class []::C2; 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

0 comments on commit 22f5504

Please sign in to comment.