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
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);
|
buf = ALLOCA_N(char, i+2);
|
||||||
code = p;
|
code = p;
|
||||||
caret = p2 = buf;
|
caret = p2 = buf;
|
||||||
i = (int)(parser->tokp - p);
|
if (p <= parser->tokp) {
|
||||||
while (i-- > 0) {
|
while (p < parser->tokp) {
|
||||||
*p2++ = *p++ == '\t' ? '\t' : ' ';
|
*p2++ = *p++ == '\t' ? '\t' : ' ';
|
||||||
|
}
|
||||||
|
*p2++ = '^';
|
||||||
|
p++;
|
||||||
}
|
}
|
||||||
*p2++ = '^';
|
if (lex_p > p) {
|
||||||
if (lex_p > parser->tokp + 1) {
|
memset(p2, '~', (lex_p - p));
|
||||||
memset(p2, '~', (lex_p - parser->tokp) - 1);
|
p2 += (lex_p - p);
|
||||||
p2 += (lex_p - parser->tokp) - 1;
|
|
||||||
}
|
}
|
||||||
*p2 = '\0';
|
*p2 = '\0';
|
||||||
newline = "\n";
|
newline = "\n";
|
||||||
|
@ -1001,6 +1001,12 @@ x = __ENCODING__
|
|||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_unexpected_token_error
|
||||||
|
assert_raise(SyntaxError) do
|
||||||
|
eval('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
def test_past_scope_variable
|
def test_past_scope_variable
|
||||||
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
|
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user