mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: check multibyte char
* parse.y (parser_precise_mbclen): check invalid multibyte char at skipping strings following `?x` literal string, not to stuck in a infinite loop. [ruby-core:81746] [Bug #13672] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f61e8084bb
commit
d391697331
2 changed files with 17 additions and 7 deletions
22
parse.y
22
parse.y
|
@ -4947,7 +4947,6 @@ ripper_dispatch_delayed_token(struct parser_params *parser, int t)
|
|||
|
||||
#define parser_encoding_name() (current_enc->name)
|
||||
#define parser_mbclen() mbclen((lex_p-1),lex_pend,current_enc)
|
||||
#define parser_precise_mbclen() rb_enc_precise_mbclen((lex_p-1),lex_pend,current_enc)
|
||||
#define is_identchar(p,e,enc) (rb_enc_isalnum((unsigned char)(*(p)),(enc)) || (*(p)) == '_' || !ISASCII(*(p)))
|
||||
#define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,current_enc))
|
||||
|
||||
|
@ -5018,6 +5017,17 @@ token_info_pop_gen(struct parser_params *parser, const char *token, size_t len)
|
|||
xfree(ptinfo);
|
||||
}
|
||||
|
||||
static int
|
||||
parser_precise_mbclen(struct parser_params *parser, const char *p)
|
||||
{
|
||||
int len = rb_enc_precise_mbclen(p, lex_pend, current_enc);
|
||||
if (!MBCLEN_CHARFOUND_P(len)) {
|
||||
compile_error(PARSER_ARG "invalid multibyte char (%s)", parser_encoding_name());
|
||||
return -1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int
|
||||
parser_yyerror(struct parser_params *parser, const char *msg)
|
||||
{
|
||||
|
@ -5930,11 +5940,8 @@ dispose_string(VALUE str)
|
|||
static int
|
||||
parser_tokadd_mbchar(struct parser_params *parser, int c)
|
||||
{
|
||||
int len = parser_precise_mbclen();
|
||||
if (!MBCLEN_CHARFOUND_P(len)) {
|
||||
compile_error(PARSER_ARG "invalid multibyte char (%s)", parser_encoding_name());
|
||||
return -1;
|
||||
}
|
||||
int len = parser_precise_mbclen(parser, lex_p-1);
|
||||
if (len < 0) return -1;
|
||||
tokadd(c);
|
||||
lex_p += --len;
|
||||
if (len > 0) tokcopy(len);
|
||||
|
@ -7426,7 +7433,8 @@ parse_qmark(struct parser_params *parser, int space_seen)
|
|||
if (space_seen) {
|
||||
const char *start = lex_p - 1, *p = start;
|
||||
do {
|
||||
int n = rb_enc_precise_mbclen(p, lex_pend, current_enc);
|
||||
int n = parser_precise_mbclen(parser, p);
|
||||
if (n < 0) return -1;
|
||||
p += n;
|
||||
} while (p < lex_pend && is_identchar(p, lex_pend, current_enc));
|
||||
rb_warn2("`?' just followed by `%.*s' is interpreted as" \
|
||||
|
|
|
@ -512,6 +512,8 @@ class TestParse < Test::Unit::TestCase
|
|||
assert_raise(SyntaxError) { eval("?\v") }
|
||||
assert_raise(SyntaxError) { eval("?\r") }
|
||||
assert_raise(SyntaxError) { eval("?\f") }
|
||||
assert_raise(SyntaxError) { eval("?\f") }
|
||||
assert_raise(SyntaxError) { eval(" ?a\x8a".force_encoding("utf-8")) }
|
||||
assert_equal("\u{1234}", eval("?\u{1234}"))
|
||||
assert_equal("\u{1234}", eval('?\u{1234}'))
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue