summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-20 06:01:57 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-20 06:01:57 +0000
commitaba824fece59d1afffa78d145a4f301f7fdc3688 (patch)
tree89173d1abb36ebd286ea8f1bbb33fad496a4b0f3 /parse.y
parent035917adc127083ac851394e56ba3636b58e4823 (diff)
parse.y: junk sigil only names
* parse.y (intern_str): sigil only names are junk, at least one identifier character is needed. [ruby-dev:47723] [Bug #8928] * parse.y (rb_enc_symname_type): fix out of bound access. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y9
1 files changed, 8 insertions, 1 deletions
diff --git a/parse.y b/parse.y
index f704930d5a..e20354909b 100644
--- a/parse.y
+++ b/parse.y
@@ -10367,6 +10367,7 @@ rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int a
if (m >= e || (*m != '_' && !rb_enc_isalpha(*m, enc) && ISASCII(*m)))
return -1;
while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
+ if (m >= e) break;
switch (*m) {
case '!': case '?':
if (type == ID_GLOBAL || type == ID_CLASS || type == ID_INSTANCE) return -1;
@@ -10484,7 +10485,8 @@ intern_str(VALUE str)
enc = rb_enc_get(str);
symenc = enc;
- if (rb_cString && !rb_enc_asciicompat(enc)) {
+ if (!len || (rb_cString && !rb_enc_asciicompat(enc))) {
+ junk:
id = ID_JUNK;
goto new_id;
}
@@ -10492,6 +10494,7 @@ intern_str(VALUE str)
id = 0;
switch (*m) {
case '$':
+ if (len < 2) goto junk;
id |= ID_GLOBAL;
if ((mb = is_special_global_name(++m, e, enc)) != 0) {
if (!--mb) symenc = rb_usascii_encoding();
@@ -10500,10 +10503,12 @@ intern_str(VALUE str)
break;
case '@':
if (m[1] == '@') {
+ if (len < 3) goto junk;
m++;
id |= ID_CLASS;
}
else {
+ if (len < 2) goto junk;
id |= ID_INSTANCE;
}
m++;
@@ -10530,6 +10535,8 @@ intern_str(VALUE str)
}
if (name[last] == '=') {
/* attribute assignment */
+ if (!rb_enc_symname2_p(name, last, enc))
+ goto junk;
id = rb_intern3(name, last, enc);
if (id > tLAST_OP_ID && !is_attrset_id(id)) {
enc = rb_enc_get(rb_id2str(id));