aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-19 02:19:45 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-19 02:19:45 +0000
commitc82488b81d87f25663c9eaf4fae493d6bd2432ce (patch)
treed3e0b148629d6a8c7e14eaeed0499ba6ecb2bdca /variable.c
parent0aaeb888d9d3db0016e1b321446dd2b6a599e812 (diff)
downloadruby-c82488b81d87f25663c9eaf4fae493d6bd2432ce.tar.gz
variable.c: consider length
* variable.c (rb_path_to_class): consider the string length instead of a terminator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/variable.c b/variable.c
index 80acee46ea..4d3222b5db 100644
--- a/variable.c
+++ b/variable.c
@@ -389,7 +389,7 @@ VALUE
rb_path_to_class(VALUE pathname)
{
rb_encoding *enc = rb_enc_get(pathname);
- const char *pbeg, *p, *path = RSTRING_PTR(pathname);
+ const char *pbeg, *pend, *p, *path = RSTRING_PTR(pathname);
ID id;
VALUE c = rb_cObject;
@@ -397,15 +397,16 @@ rb_path_to_class(VALUE pathname)
rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
}
pbeg = p = path;
- if (path[0] == '#') {
+ pend = path + RSTRING_LEN(pathname);
+ if (path == pend || path[0] == '#') {
rb_raise(rb_eArgError, "can't retrieve anonymous class %"PRIsVALUE,
QUOTE(pathname));
}
- while (*p) {
- while (*p && *p != ':') p++;
+ while (p < pend) {
+ while (p < pend && *p != ':') p++;
id = rb_check_id_cstr(pbeg, p-pbeg, enc);
- if (p[0] == ':') {
- if (p[1] != ':') goto undefined_class;
+ if (p < pend && p[0] == ':') {
+ if ((size_t)(pend - p) < 2 || p[1] != ':') goto undefined_class;
p += 2;
pbeg = p;
}