This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #128988) preserve PL_oldoldbufptr is preserved in scan_heredoc()
authorTony Cook <tony@develop-help.com>
Mon, 22 Aug 2016 03:56:26 +0000 (13:56 +1000)
committerTony Cook <tony@develop-help.com>
Wed, 7 Sep 2016 00:19:21 +0000 (10:19 +1000)
In some cases this is used in building error messages.

t/op/heredoc.t
toke.c

index 90ba606..f47f7ce 100644 (file)
@@ -7,7 +7,7 @@ BEGIN {
 }
 
 use strict;
-plan(tests => 41);
+plan(tests => 42);
 
 
 # heredoc without newline (#65838)
@@ -99,6 +99,15 @@ HEREDOC
         "don't use an invalid oldoldbufptr"
     );
 
+    # also read freed memory, but got an invalid oldoldbufptr in a different way
+    fresh_perl_like(
+        qq(<<\n\$          \n),
+        # valgrind and asan reports an error between these two lines
+        qr/^Use of bare << to mean <<"" is deprecated at - line 1\.\s+Final \$/,
+        {},
+        "don't use an invalid oldoldbufptr (some more)"
+    );
+
     # [perl #125540] this asserted or crashed
     fresh_perl_like(
        q(map d$#<<<<),
diff --git a/toke.c b/toke.c
index a1cdda8..75508f1 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -9724,6 +9724,7 @@ S_scan_heredoc(pTHX_ char *s)
     {
       SV *linestr_save;
       char *oldbufptr_save;
+      char **oldoldbufptr_save;
      streaming:
       sv_setpvs(tmpstr,"");   /* avoid "uninitialized" warning */
       term = PL_tokenbuf[1];
@@ -9731,6 +9732,7 @@ S_scan_heredoc(pTHX_ char *s)
       linestr_save = PL_linestr; /* must restore this afterwards */
       d = s;                    /* and this */
       oldbufptr_save = PL_oldbufptr;
+      oldoldbufptr_save = PL_oldoldbufptr;
       PL_linestr = newSVpvs("");
       PL_bufend = SvPVX(PL_linestr);
       while (1) {
@@ -9748,6 +9750,7 @@ S_scan_heredoc(pTHX_ char *s)
            SvREFCNT_dec_NN(PL_linestr);
            PL_linestr = linestr_save;
             PL_oldbufptr = oldbufptr_save;
+            PL_oldoldbufptr = oldoldbufptr_save;
            goto interminable;
        }
        CopLINE_set(PL_curcop, origline);
@@ -9783,6 +9786,7 @@ S_scan_heredoc(pTHX_ char *s)
            PL_linestart = SvPVX(linestr_save);
            PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
             PL_oldbufptr = oldbufptr_save;
+            PL_oldoldbufptr = oldoldbufptr_save;
            s = d;
            break;
        }