mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Prohibit Class#allocate in a different way
The method introduced by #5979 causes a fault by swapping classes. ```console % bin/mruby -e 'Method = Proc; p Object.method(:inspect)' zsh: segmentation fault (core dumped) bin/mruby -e 'Method = Proc; p Object.method(:inspect)' ``` After applying this patch, a `TypeError` exception will be raised. ```console % bin/mruby -e 'Method = Proc; p Object.method(:inspect)' trace (most recent call last): [1] -e:1 -e:1:in method: allocation failure of Proc (TypeError) ``` However, if the `mrb_vtype` is the same object, the same care must still be taken as before. ```console % bin/mruby -e 'Method = Binding; p method(:puts).eval("12345")' trace (most recent call last): [1] -e:1 -e:1:in eval: wrong argument type nil (expected Proc) (TypeError) ```
This commit is contained in:
+3
-3
@@ -1949,10 +1949,10 @@ mrb_instance_alloc(mrb_state *mrb, mrb_value cv)
|
||||
else if (ttype == 0) {
|
||||
ttype = MRB_TT_OBJECT;
|
||||
}
|
||||
if (MRB_UNDEF_ALLOCATOR_P(c)) {
|
||||
mrb_raisef(mrb, E_TYPE_ERROR, "allocator undefined for %v", cv);
|
||||
}
|
||||
if (ttype <= MRB_TT_CPTR) {
|
||||
if (ttype == MRB_TT_UNDEF) {
|
||||
mrb_raisef(mrb, E_TYPE_ERROR, "allocator undefined for %v", cv);
|
||||
}
|
||||
mrb_raisef(mrb, E_TYPE_ERROR, "can't create instance of %v", cv);
|
||||
}
|
||||
o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c);
|
||||
|
||||
Reference in New Issue
Block a user