ruby-changes:47126
From: usa <ko1@a...>
Date: Fri, 30 Jun 2017 22:06:04 +0900 (JST)
Subject: [ruby-changes:47126] usa:r59241 (ruby_2_3): merge revision(s) 59161: [Backport #13672]
usa 2017-06-30 22:05:58 +0900 (Fri, 30 Jun 2017) New Revision: 59241 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59241 Log: merge revision(s) 59161: [Backport #13672] 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] Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/ChangeLog branches/ruby_2_3/parse.y branches/ruby_2_3/test/ruby/test_parse.rb branches/ruby_2_3/version.h Index: ruby_2_3/parse.y =================================================================== --- ruby_2_3/parse.y (revision 59240) +++ ruby_2_3/parse.y (revision 59241) @@ -5333,7 +5333,6 @@ ripper_dispatch_delayed_token(struct par https://github.com/ruby/ruby/blob/trunk/ruby_2_3/parse.y#L5333 #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)) @@ -5407,6 +5406,18 @@ token_info_pop(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/ruby_2_3/parse.y#L5406 } 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) { #ifndef RIPPER @@ -6186,11 +6197,8 @@ dispose_string(VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/parse.y#L6197 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); Index: ruby_2_3/test/ruby/test_parse.rb =================================================================== --- ruby_2_3/test/ruby/test_parse.rb (revision 59240) +++ ruby_2_3/test/ruby/test_parse.rb (revision 59241) @@ -512,6 +512,8 @@ class TestParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_parse.rb#L512 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 Index: ruby_2_3/ChangeLog =================================================================== --- ruby_2_3/ChangeLog (revision 59240) +++ ruby_2_3/ChangeLog (revision 59241) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1 +Fri Jun 30 22:05:39 2017 Nobuyoshi Nakada <nobu@r...> + + * parse.y (parser_precise_mbclen): check invalid multibyte char at + skipping strings following ?x literal string, not to stuck in a + infinite loop. [Bug #13672] + Fri Jun 30 22:00:56 2017 Nobuyoshi Nakada <nobu@r...> * ext/pathname/lib/pathname.rb (Pathname#plus): UNC root pathname needs Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 59240) +++ ruby_2_3/version.h (revision 59241) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.5" #define RUBY_RELEASE_DATE "2017-06-30" -#define RUBY_PATCHLEVEL 337 +#define RUBY_PATCHLEVEL 338 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_3 =================================================================== --- ruby_2_3 (revision 59240) +++ ruby_2_3 (revision 59241) Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r59161 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/