b8876f
From 2f221fc2333bd87615c03354b591b390e8b06715 Mon Sep 17 00:00:00 2001
b8876f
From: Tony Cook <tony@develop-help.com>
b8876f
Date: Tue, 24 Jan 2017 11:14:28 +1100
b8876f
Subject: [PATCH] (perl #129274) avoid treating the # in $# as a comment intro
b8876f
MIME-Version: 1.0
b8876f
Content-Type: text/plain; charset=UTF-8
b8876f
Content-Transfer-Encoding: 8bit
b8876f
b8876f
Petr Písař: Ported to 5.24.1:
b8876f
b8876f
commit 71776ae4fad9a7659deefe0c2376d45b873ffd6a
b8876f
Author: Tony Cook <tony@develop-help.com>
b8876f
Date:   Tue Jan 24 11:14:28 2017 +1100
b8876f
b8876f
    (perl #129274) avoid treating the # in $# as a comment intro
b8876f
b8876f
Signed-off-by: Petr Písař <ppisar@redhat.com>
b8876f
---
b8876f
 t/op/lex.t | 15 ++++++++++++++-
b8876f
 toke.c     |  4 +++-
b8876f
 2 files changed, 17 insertions(+), 2 deletions(-)
b8876f
b8876f
diff --git a/t/op/lex.t b/t/op/lex.t
b8876f
index 9ada592..d679d7c 100644
b8876f
--- a/t/op/lex.t
b8876f
+++ b/t/op/lex.t
b8876f
@@ -7,7 +7,7 @@ use warnings;
b8876f
 
b8876f
 BEGIN { chdir 't' if -d 't'; require './test.pl'; }
b8876f
 
b8876f
-plan(tests => 27);
b8876f
+plan(tests => 28);
b8876f
 
b8876f
 {
b8876f
     no warnings 'deprecated';
b8876f
@@ -223,3 +223,16 @@ fresh_perl_like(
b8876f
     {},
b8876f
     '[perl #129336] - #!perl -i argument handling'
b8876f
 );
b8876f
+
b8876f
+# probably only failed under ASAN
b8876f
+fresh_perl_is(
b8876f
+    "stat\tt\$#0",
b8876f
+    <<'EOM',
b8876f
+$# is no longer supported at - line 1.
b8876f
+Number found where operator expected at - line 1, near "$#0"
b8876f
+	(Missing operator before 0?)
b8876f
+Can't call method "t" on an undefined value at - line 1.
b8876f
+EOM
b8876f
+    {},
b8876f
+    "[perl #129273] heap use after free or overflow"
b8876f
+);
b8876f
diff --git a/toke.c b/toke.c
b8876f
index 576ce72..630fc59 100644
b8876f
--- a/toke.c
b8876f
+++ b/toke.c
b8876f
@@ -4090,7 +4090,9 @@ S_intuit_method(pTHX_ char *start, SV *ioname, CV *cv)
b8876f
 	if (cv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY
b8876f
             || isUPPER(*PL_tokenbuf))
b8876f
 	    return 0;
b8876f
-	s = skipspace(s);
b8876f
+        /* this could be $# */
b8876f
+        if (isSPACE(*s))
b8876f
+            s = skipspace(s);
b8876f
 	PL_bufptr = start;
b8876f
 	PL_expect = XREF;
b8876f
 	return *s == '(' ? FUNCMETH : METHOD;
b8876f
-- 
b8876f
2.7.4
b8876f