aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-28 02:02:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-28 02:02:38 +0000
commit76a3d5633582c269c9c3a0b0d259b5f7b24df5c9 (patch)
tree193a7f9efe476201b6f5b413a0407e1f3476fa25
parentb120d0fcddd219e4d23a2027a4b3599d772158b8 (diff)
downloadruby-76a3d5633582c269c9c3a0b0d259b5f7b24df5c9.tar.gz
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
-rw-r--r--parse.y18
-rw-r--r--test/ruby/test_parse.rb6
2 files changed, 16 insertions, 8 deletions
diff --git a/parse.y b/parse.y
index adae297678..833eda062c 100644
--- a/parse.y
+++ b/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' : ' ';
- }
- *p2++ = '^';
- if (lex_p > parser->tokp + 1) {
- memset(p2, '~', (lex_p - parser->tokp) - 1);
- p2 += (lex_p - parser->tokp) - 1;
+ if (p <= parser->tokp) {
+ while (p < parser->tokp) {
+ *p2++ = *p++ == '\t' ? '\t' : ' ';
+ }
+ *p2++ = '^';
+ p++;
+ }
+ if (lex_p > p) {
+ memset(p2, '~', (lex_p - p));
+ p2 += (lex_p - p);
}
*p2 = '\0';
newline = "\n";
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 030442f9e9..d2fc5f0721 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -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")}}