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

ruby-changes:26500

From: nobu <ko1@a...>
Date: Sat, 22 Dec 2012 19:26:52 +0900 (JST)
Subject: [ruby-changes:26500] nobu:r38551 (trunk): object.c: check more strictly

nobu	2012-12-22 19:26:40 +0900 (Sat, 22 Dec 2012)

  New Revision: 38551

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

  Log:
    object.c: check more strictly
    
    * object.c (rb_mod_const_get): check more strictly.  [ruby-dev:46748]
      [Bug #7573]

  Modified files:
    trunk/ChangeLog
    trunk/object.c
    trunk/test/ruby/test_module.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38550)
+++ ChangeLog	(revision 38551)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Dec 22 19:26:35 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* object.c (rb_mod_const_get): check more strictly.  [ruby-dev:46748]
+	  [Bug #7573]
+
 Wed Dec 19 02:34:48 2012  CHIKANAGA Tomoyuki  <nagachika@r...>
 
 	* cont.c (rb_fiber_start): in case of jump with TAG_FATAL,
Index: object.c
===================================================================
--- object.c	(revision 38550)
+++ object.c	(revision 38551)
@@ -1959,7 +1959,7 @@ rb_mod_const_get(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/object.c#L1959
 	rb_raise(rb_eNameError, "wrong constant name %s", path);
     }
 
-    if (p[0] == ':' && p[1] == ':') {
+    if (p + 2 < pend && p[0] == ':' && p[1] == ':') {
 	mod = rb_cObject;
 	p += 2;
 	pbeg = p;
@@ -1981,8 +1981,8 @@ rb_mod_const_get(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/object.c#L1981
 	else {
 	    part = rb_str_subseq(name, pbeg-path, p-pbeg);
 	}
-	if (p[0] == ':') {
-	    if (p[1] != ':') {
+	if (p < pend && p[0] == ':') {
+	    if (p + 2 >= pend || p[1] != ':') {
 		rb_raise(rb_eNameError, "wrong constant name %s", path);
             }
 	    p += 2;
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 38550)
+++ test/ruby/test_module.rb	(revision 38551)
@@ -246,8 +246,9 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L246
       ":Object",
       "",
       ":",
-    ].each do |name|
-      e = assert_raises(NameError) {
+      ["String::", "[Bug #7573]"],
+    ].each do |name, msg|
+      e = assert_raises(NameError, "#{msg}#{': ' if msg}wrong constant name #{name.dump}") {
         Object.const_get name
       }
       assert_equal("wrong constant name %s" % name, e.message)

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

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