ruby-changes:26415
From: nobu <ko1@a...>
Date: Wed, 19 Dec 2012 19:34:25 +0900 (JST)
Subject: [ruby-changes:26415] nobu:r38466 (trunk): object.c: nul in const name
nobu 2012-12-19 19:34:13 +0900 (Wed, 19 Dec 2012) New Revision: 38466 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38466 Log: object.c: nul in const name * object.c (rb_mod_const_get): nul byte is invalid as constant name. Modified files: trunk/ChangeLog trunk/object.c trunk/test/ruby/test_module.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38465) +++ ChangeLog (revision 38466) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Dec 19 19:34:03 2012 Nobuyoshi Nakada <nobu@r...> + + * object.c (rb_mod_const_get): nul byte is invalid as constant name. + Wed Dec 19 17:54:18 2012 Masaya Tarui <tarui@r...> * vm_trace.c (rb_threadptr_exec_event_hooks): get rid of race Index: object.c =================================================================== --- object.c (revision 38465) +++ object.c (revision 38466) @@ -1920,7 +1920,7 @@ rb_mod_const_get(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/object.c#L1920 { VALUE name, recur; rb_encoding *enc; - const char *pbeg, *p, *path; + const char *pbeg, *p, *path, *pend; ID id; if (argc == 1) { @@ -1946,6 +1946,7 @@ rb_mod_const_get(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/object.c#L1946 } pbeg = p = path; + pend = path + RSTRING_LEN(name); if (!*p) { rb_raise(rb_eNameError, "wrong constant name %s", path); @@ -1957,10 +1958,10 @@ rb_mod_const_get(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/object.c#L1958 pbeg = p; } - while (*p) { + while (p < pend) { VALUE part; - while (*p && *p != ':') p++; + while (p < pend && *p != ':') p++; if (pbeg == p) { rb_raise(rb_eNameError, "wrong constant name %s", path); Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 38465) +++ test/ruby/test_module.rb (revision 38466) @@ -583,9 +583,18 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L583 def test_const_get_invalid_name c1 = Class.new + assert_raise(NameError) { c1.const_get(:foo) } + bug5084 = '[ruby-dev:44200]' + assert_raise(TypeError, bug5084) { c1.const_get(1) } + assert_raise(NameError) { Object.const_get("String\0") } + end + + def test_const_defined_invalid_name + c1 = Class.new assert_raise(NameError) { c1.const_defined?(:foo) } bug5084 = '[ruby-dev:44200]' assert_raise(TypeError, bug5084) { c1.const_defined?(1) } + assert_raise(NameError) { Object.const_defined?("String\0") } end def test_const_get_no_inherited -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/