[前][次][番号順一覧][スレッド一覧]

ruby-changes:35633

From: normal <ko1@a...>
Date: Fri, 26 Sep 2014 05:29:26 +0900 (JST)
Subject: [ruby-changes:35633] normal:r47715 (trunk): object.c (rb_class_real): do not dereference 0 VALUE

normal	2014-09-26 05:29:15 +0900 (Fri, 26 Sep 2014)

  New Revision: 47715

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47715

  Log:
    object.c (rb_class_real): do not dereference 0 VALUE
    
    * test/ruby/test_module.rb (test_inspect_segfault):
      Test case and bug report by Thomas Stratmann.
      [ruby-core:65214] [Bug #10282]

  Modified files:
    trunk/ChangeLog
    trunk/object.c
    trunk/test/ruby/test_module.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47714)
+++ ChangeLog	(revision 47715)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Sep 26 05:21:01 2014  Eric Wong  <e@8...>
+
+	* object.c (rb_class_real): do not dereference 0 VALUE
+
+	* test/ruby/test_module.rb (test_inspect_segfault):
+	  Test case and bug report by Thomas Stratmann.
+	  [ruby-core:65214] [Bug #10282]
+
 Fri Sep 26 05:12:10 2014  Eric Wong  <e@8...>
 
 	* man/ruby.1: document stack size env variables
Index: object.c
===================================================================
--- object.c	(revision 47714)
+++ object.c	(revision 47715)
@@ -206,9 +206,8 @@ rb_obj_not_equal(VALUE obj1, VALUE obj2) https://github.com/ruby/ruby/blob/trunk/object.c#L206
 VALUE
 rb_class_real(VALUE cl)
 {
-    if (cl == 0)
-        return 0;
-    while ((RBASIC(cl)->flags & FL_SINGLETON) || BUILTIN_TYPE(cl) == T_ICLASS) {
+    while (cl &&
+        ((RBASIC(cl)->flags & FL_SINGLETON) || BUILTIN_TYPE(cl) == T_ICLASS)) {
 	cl = RCLASS_SUPER(cl);
     }
     return cl;
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 47714)
+++ test/ruby/test_module.rb	(revision 47715)
@@ -1971,6 +1971,30 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1971
     }
   end
 
+  def test_inspect_segfault
+    bug_10282 = '[ruby-core:65214] [Bug #10282]'
+    assert_separately [], <<-RUBY
+      module ShallowInspect
+        def shallow_inspect
+          "foo"
+        end
+      end
+
+      module InspectIsShallow
+        include ShallowInspect
+        alias_method :inspect, :shallow_inspect
+      end
+
+      class A
+      end
+
+      A.prepend InspectIsShallow
+
+      expect = "#<Method: A(Object)#inspect(shallow_inspect)>"
+      assert_equal expect, A.new.method(:inspect).inspect, "#{bug_10282}"
+    RUBY
+  end
+
   private
 
   def assert_top_method_is_private(method)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]