aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
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 /parse.y
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
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y18
1 files changed, 10 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";