diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-20 06:01:57 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-20 06:01:57 +0000 |
commit | aba824fece59d1afffa78d145a4f301f7fdc3688 (patch) | |
tree | 89173d1abb36ebd286ea8f1bbb33fad496a4b0f3 /parse.y | |
parent | 035917adc127083ac851394e56ba3636b58e4823 (diff) | |
download | ruby-aba824fece59d1afffa78d145a4f301f7fdc3688.tar.gz |
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.y | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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)); |