ruby-changes:45177
From: nobu <ko1@a...>
Date: Mon, 2 Jan 2017 09:22:50 +0900 (JST)
Subject: [ruby-changes:45177] nobu:r57250 (trunk): object.c: rb_class_alloc
nobu 2017-01-02 09:22:46 +0900 (Mon, 02 Jan 2017) New Revision: 57250 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57250 Log: 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] Modified files: trunk/object.c Index: object.c =================================================================== --- object.c (revision 57249) +++ object.c (revision 57250) @@ -1840,8 +1840,8 @@ rb_undefined_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/object.c#L1840 * */ -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) https://github.com/ruby/ruby/blob/trunk/object.c#L1867 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 *ar https://github.com/ruby/ruby/blob/trunk/object.c#L1898 { 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) https://github.com/ruby/ruby/blob/trunk/object.c#L3593 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/