From 03b8cb95481fce36c0460e1c90564d08249312fe Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 2 Jan 2017 00:22:46 +0000 Subject: object.c: rb_class_alloc * object.c (rb_obj_alloc): add pathological check of klass for extension libraries which do not check given arguments properly. [ruby-core:78934] [Bug #13093] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 67d23ef830..3a9a556947 100644 --- a/object.c +++ b/object.c @@ -1840,8 +1840,8 @@ rb_undefined_alloc(VALUE klass) * */ -VALUE -rb_obj_alloc(VALUE klass) +static VALUE +rb_class_alloc(VALUE klass) { VALUE obj; rb_alloc_func_t allocator; @@ -1867,6 +1867,13 @@ rb_obj_alloc(VALUE klass) return obj; } +VALUE +rb_obj_alloc(VALUE klass) +{ + Check_Type(klass, T_CLASS); + return rb_class_alloc(klass); +} + static VALUE rb_class_allocate_instance(VALUE klass) { @@ -1891,7 +1898,7 @@ rb_class_s_new(int argc, const VALUE *argv, VALUE klass) { VALUE obj; - obj = rb_obj_alloc(klass); + obj = rb_class_alloc(klass); rb_obj_call_init(obj, argc, argv); return obj; @@ -3586,7 +3593,7 @@ InitVM_Object(void) rb_define_method(rb_cModule, "deprecate_constant", rb_mod_deprecate_constant, -1); /* in variable.c */ rb_define_method(rb_cModule, "singleton_class?", rb_mod_singleton_p, 0); - rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0); + rb_define_method(rb_cClass, "allocate", rb_class_alloc, 0); rb_define_method(rb_cClass, "new", rb_class_s_new, -1); rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1); rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0); -- cgit v1.2.3