object.c: nul in const name
* object.c (rb_mod_const_get): nul byte is invalid as constant name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
542a12d673
commit
c3026b723c
@ -1,3 +1,7 @@
|
|||||||
|
Wed Dec 19 19:34:03 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* object.c (rb_mod_const_get): nul byte is invalid as constant name.
|
||||||
|
|
||||||
Wed Dec 19 17:54:18 2012 Masaya Tarui <tarui@ruby-lang.org>
|
Wed Dec 19 17:54:18 2012 Masaya Tarui <tarui@ruby-lang.org>
|
||||||
|
|
||||||
* vm_trace.c (rb_threadptr_exec_event_hooks): get rid of race
|
* vm_trace.c (rb_threadptr_exec_event_hooks): get rid of race
|
||||||
|
7
object.c
7
object.c
@ -1920,7 +1920,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
|
|||||||
{
|
{
|
||||||
VALUE name, recur;
|
VALUE name, recur;
|
||||||
rb_encoding *enc;
|
rb_encoding *enc;
|
||||||
const char *pbeg, *p, *path;
|
const char *pbeg, *p, *path, *pend;
|
||||||
ID id;
|
ID id;
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
@ -1946,6 +1946,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pbeg = p = path;
|
pbeg = p = path;
|
||||||
|
pend = path + RSTRING_LEN(name);
|
||||||
|
|
||||||
if (!*p) {
|
if (!*p) {
|
||||||
rb_raise(rb_eNameError, "wrong constant name %s", path);
|
rb_raise(rb_eNameError, "wrong constant name %s", path);
|
||||||
@ -1957,10 +1958,10 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
|
|||||||
pbeg = p;
|
pbeg = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*p) {
|
while (p < pend) {
|
||||||
VALUE part;
|
VALUE part;
|
||||||
|
|
||||||
while (*p && *p != ':') p++;
|
while (p < pend && *p != ':') p++;
|
||||||
|
|
||||||
if (pbeg == p) {
|
if (pbeg == p) {
|
||||||
rb_raise(rb_eNameError, "wrong constant name %s", path);
|
rb_raise(rb_eNameError, "wrong constant name %s", path);
|
||||||
|
@ -582,10 +582,19 @@ class TestModule < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_const_get_invalid_name
|
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
|
c1 = Class.new
|
||||||
assert_raise(NameError) { c1.const_defined?(:foo) }
|
assert_raise(NameError) { c1.const_defined?(:foo) }
|
||||||
bug5084 = '[ruby-dev:44200]'
|
bug5084 = '[ruby-dev:44200]'
|
||||||
assert_raise(TypeError, bug5084) { c1.const_defined?(1) }
|
assert_raise(TypeError, bug5084) { c1.const_defined?(1) }
|
||||||
|
assert_raise(NameError) { Object.const_defined?("String\0") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_const_get_no_inherited
|
def test_const_get_no_inherited
|
||||||
|
Loading…
x
Reference in New Issue
Block a user