diff --git a/ChangeLog b/ChangeLog index 01cdced1e5..c92347e427 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Dec 22 19:26:35 2012 Nobuyoshi Nakada + + * object.c (rb_mod_const_get): check more strictly. [ruby-dev:46748] + [Bug #7573] + Wed Dec 19 02:34:48 2012 CHIKANAGA Tomoyuki * cont.c (rb_fiber_start): in case of jump with TAG_FATAL, diff --git a/object.c b/object.c index 13765bc621..b385135019 100644 --- a/object.c +++ b/object.c @@ -1959,7 +1959,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) 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, VALUE mod) 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; diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index eb1477893b..84dedb431b 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -246,8 +246,9 @@ class TestModule < Test::Unit::TestCase ":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)