mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: fix parser_yyerror
* parse.y (parser_yyerror): fix buffer overflow at truncation of error line. [ruby-core:81790] [Bug #13687] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c28f8b0394
commit
ff36c25f47
2 changed files with 15 additions and 7 deletions
16
parse.y
16
parse.y
|
@ -5074,14 +5074,16 @@ parser_yyerror(struct parser_params *parser, const char *msg)
|
|||
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";
|
||||
|
|
|
@ -1001,6 +1001,12 @@ x = __ENCODING__
|
|||
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")}}
|
||||
|
|
Loading…
Reference in a new issue