From e6883ef68880dc6682ab8bad5c390619e672933f Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 18 Jan 2018 03:29:12 +0000 Subject: [PATCH] parse.y: fix overflow git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 3 +-- test/-ext-/ast/test_ast.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/parse.y b/parse.y index 470c37d4d9..76f134d9d6 100644 --- a/parse.y +++ b/parse.y @@ -6191,7 +6191,6 @@ parser_heredoc_identifier(struct parser_params *p) break; } - p->tokenbuf[0] = p->tokenbuf[0] + toklen() - 2; tokfix(); dispatch_scan_event(tHEREDOC_BEG); len = p->lex.pcur - p->lex.pbeg; @@ -9155,7 +9154,7 @@ void rb_parser_set_location_from_strterm_heredoc(struct parser_params *p, rb_strterm_heredoc_t *here, YYLTYPE *yylloc) { const char *eos = RSTRING_PTR(here->term); - int term_len = (int)eos[0]; + long term_len = RSTRING_LEN(here->term) - 2 + (unsigned char)eos[0]; yylloc->beg_pos.lineno = (int)here->sourceline; yylloc->beg_pos.column = (int)(here->u3.lastidx - term_len); diff --git a/test/-ext-/ast/test_ast.rb b/test/-ext-/ast/test_ast.rb index d5bdff154a..06bb0bf5e2 100644 --- a/test/-ext-/ast/test_ast.rb +++ b/test/-ext-/ast/test_ast.rb @@ -129,4 +129,12 @@ class TestAst < Test::Unit::TestCase assert_equal([], helper.errors) end end + + def test_column_with_long_heredoc_identifier + term = "A"*257 + ast = AST.parse("<<-#{term}\n""ddddddd\n#{term}\n") + node = ast.children[1] + assert_equal("NODE_STR", node.type) + assert_equal(0, node.first_column) + end end