Skip to content

Commit

Permalink
object.c: forbid uninitialized class
Browse files Browse the repository at this point in the history
* object.c (rb_class_initialize): forbid inheriting uninitialized
  class.  another class tree not based on BasicObject cannot exist.
  [ruby-core:47148][Bug ruby#6863]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Aug 16, 2012
1 parent a39b94d commit 9528358
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ module Foo; def foo; :foo; end; end
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
Expand Down

0 comments on commit 9528358

Please sign in to comment.