In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/90f2cc9a600117a49f8ee3e30cc681f062350c24?hp=b289efd9cce518a9889bdd049e2d9dad508e6bee>

- Log -----------------------------------------------------------------
commit 90f2cc9a600117a49f8ee3e30cc681f062350c24
Author: Hugo van der Sanden <[email protected]>
Date:   Sun Feb 19 10:46:09 2017 +0000

    [perl #130814] update pointer into PL_linestr after lookahead
    
    Looking ahead for the "Missing $ on loop variable" diagnostic can reallocate
    PL_linestr, invalidating our pointer. Save the offset so we can update it
    in that case.

M       toke.c

commit d7186addd1b477f6bdcef5e9d24f2125691a9082
Author: Hugo van der Sanden <[email protected]>
Date:   Sun Feb 19 11:15:38 2017 +0000

    [perl #130814] Add testcase, and new testfile t/comp/parser_run.t
    
    Sometimes it's useful to have test.pl around, but it seems inappropriate
    to pollute the existing t/comp/parser.t with that.

A       t/comp/parser_run.t
-----------------------------------------------------------------------

Summary of changes:
 t/comp/parser_run.t | 28 ++++++++++++++++++++++++++++
 toke.c              |  4 ++++
 2 files changed, 32 insertions(+)
 create mode 100644 t/comp/parser_run.t

diff --git a/t/comp/parser_run.t b/t/comp/parser_run.t
new file mode 100644
index 0000000000..2543f499b5
--- /dev/null
+++ b/t/comp/parser_run.t
@@ -0,0 +1,28 @@
+#!./perl
+
+# Parser tests that want test.pl, eg to use runperl() for tests to show
+# reads through invalid pointers.
+# Note that this should still be runnable under miniperl.
+
+BEGIN {
+    @INC = qw(. ../lib );
+    chdir 't' if -d 't';
+}
+
+require './test.pl';
+plan(1);
+
+# [perl #130814] can reallocate lineptr while looking ahead for
+# "Missing $ on loop variable" diagnostic.
+my $result = runperl(
+    prog => " foreach m0\n\$" . ("0" x 0x2000),
+    stderr => 1,
+);
+is($result, <<EXPECT);
+syntax error at -e line 3, near "foreach m0
+"
+Identifier too long at -e line 3.
+EXPECT
+
+__END__
+# ex: set ts=8 sts=4 sw=4 et:
diff --git a/toke.c b/toke.c
index 5a711d3ca3..cf3163ec20 100644
--- a/toke.c
+++ b/toke.c
@@ -7913,6 +7913,7 @@ Perl_yylex(pTHX)
                 && isIDFIRST_lazy_if_safe(s, PL_bufend, UTF))
             {
                char *p = s;
+                SSize_t s_off = s - SvPVX(PL_linestr);
 
                if ((PL_bufend - p) >= 3
                     && strEQs(p, "my") && isSPACE(*(p + 2)))
@@ -7930,6 +7931,9 @@ Perl_yylex(pTHX)
                }
                if (*p != '$' && *p != '\\')
                    Perl_croak(aTHX_ "Missing $ on loop variable");
+
+                /* The buffer may have been reallocated, update s */
+                s = SvPVX(PL_linestr) + s_off;
            }
            OPERATOR(FOR);
 

--
Perl5 Master Repository

Reply via email to