ruby-changes:47073
From: nobu <ko1@a...>
Date: Wed, 28 Jun 2017 11:02:43 +0900 (JST)
Subject: [ruby-changes:47073] nobu:r59188 (trunk): parse.y: fix parser_yyerror
nobu 2017-06-28 11:02:38 +0900 (Wed, 28 Jun 2017) New Revision: 59188 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59188 Log: parse.y: fix parser_yyerror * parse.y (parser_yyerror): fix buffer overflow at truncation of error line. [ruby-core:81790] [Bug #13687] Modified files: trunk/parse.y trunk/test/ruby/test_parse.rb Index: parse.y =================================================================== --- parse.y (revision 59187) +++ parse.y (revision 59188) @@ -5074,14 +5074,16 @@ parser_yyerror(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L5074 buf = ALLOCA_N(char, i+2); code = p; caret = p2 = buf; - i = (int)(parser->tokp - p); - while (i-- > 0) { - *p2++ = *p++ == '\t' ? '\t' : ' '; + if (p <= parser->tokp) { + while (p < parser->tokp) { + *p2++ = *p++ == '\t' ? '\t' : ' '; + } + *p2++ = '^'; + p++; } - *p2++ = '^'; - if (lex_p > parser->tokp + 1) { - memset(p2, '~', (lex_p - parser->tokp) - 1); - p2 += (lex_p - parser->tokp) - 1; + if (lex_p > p) { + memset(p2, '~', (lex_p - p)); + p2 += (lex_p - p); } *p2 = '\0'; newline = "\n"; Index: test/ruby/test_parse.rb =================================================================== --- test/ruby/test_parse.rb (revision 59187) +++ test/ruby/test_parse.rb (revision 59188) @@ -1001,6 +1001,12 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1001 end; end + def test_unexpected_token_error + assert_raise(SyntaxError) do + eval('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') + end + end + =begin def test_past_scope_variable assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}} -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/