object.c: forbid uninitialized class

* object.c (rb_class_initialize): forbid inheriting uninitialized
  class.  another class tree not based on BasicObject cannot exist.
  [ruby-core:47148][Bug #6863]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-08-16 10:15:28 +00:00
parent a39b94d302
commit 9528358120
3 changed files with 11 additions and 0 deletions

View File

@ -1,3 +1,9 @@
Thu Aug 16 19:15:23 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* object.c (rb_class_initialize): forbid inheriting uninitialized
class. another class tree not based on BasicObject cannot exist.
[ruby-core:47148][Bug #6863]
Thu Aug 16 11:52:06 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/-ext-/test_printf.rb (Test_SPrintf#test_{taint,untrust}): use

View File

@ -1616,6 +1616,9 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
else {
rb_scan_args(argc, argv, "01", &super);
rb_check_inheritable(super);
if (super != rb_cBasicObject && !RCLASS_SUPER(super)) {
rb_raise(rb_eTypeError, "can't inherit uninitialized class");
}
}
RCLASS_SUPER(klass) = super;
rb_make_metaclass(klass, RBASIC(super)->klass);

View File

@ -203,6 +203,8 @@ class TestClass < Test::Unit::TestCase
def test_uninitialized
assert_raise(TypeError) { Class.allocate.new }
assert_raise(TypeError) { Class.allocate.superclass }
bug6863 = '[ruby-core:47148]'
assert_raise(TypeError, bug6863) { Class.new(Class.allocate) }
end
def test_nonascii_name