Blame SOURCES/perl-5.25.2-perl-128597-Crash-from-gp_free-ckWARN_d.patch

276c98
From a2637ca0a3fec01b80d7ea5ba62802354fd5e6f3 Mon Sep 17 00:00:00 2001
276c98
From: Father Chrysostomos <sprout@cpan.org>
276c98
Date: Mon, 11 Jul 2016 14:49:17 -0700
276c98
Subject: [PATCH] [perl #128597] Crash from gp_free/ckWARN_d
276c98
MIME-Version: 1.0
276c98
Content-Type: text/plain; charset=UTF-8
276c98
Content-Transfer-Encoding: 8bit
276c98
276c98
See the explanation in the test added and in the RT ticket.
276c98
276c98
The solution is to make the warn macros check that PL_curcop
276c98
is non-null.
276c98
276c98
Signed-off-by: Petr Písař <ppisar@redhat.com>
276c98
---
276c98
 regen/warnings.pl |  6 ++++--
276c98
 t/op/gv.t         | 18 +++++++++++++++++-
276c98
 warnings.h        |  6 ++++--
276c98
 3 files changed, 25 insertions(+), 5 deletions(-)
276c98
276c98
diff --git a/regen/warnings.pl b/regen/warnings.pl
276c98
index 815c735..94cd7a4 100644
276c98
--- a/regen/warnings.pl
276c98
+++ b/regen/warnings.pl
276c98
@@ -358,8 +358,10 @@ EOM
276c98
 
276c98
   print $warn <<'EOM';
276c98
 
276c98
-#define isLEXWARN_on 	cBOOL(PL_curcop->cop_warnings != pWARN_STD)
276c98
-#define isLEXWARN_off	cBOOL(PL_curcop->cop_warnings == pWARN_STD)
276c98
+#define isLEXWARN_on \
276c98
+	cBOOL(PL_curcop && PL_curcop->cop_warnings != pWARN_STD)
276c98
+#define isLEXWARN_off \
276c98
+	cBOOL(!PL_curcop || PL_curcop->cop_warnings == pWARN_STD)
276c98
 #define isWARN_ONCE	(PL_dowarn & (G_WARN_ON|G_WARN_ONCE))
276c98
 #define isWARN_on(c,x)	(IsSet((U8 *)(c + 1), 2*(x)))
276c98
 #define isWARNf_on(c,x)	(IsSet((U8 *)(c + 1), 2*(x)+1))
276c98
diff --git a/t/op/gv.t b/t/op/gv.t
276c98
index d71fd0a..03ae46e 100644
276c98
--- a/t/op/gv.t
276c98
+++ b/t/op/gv.t
276c98
@@ -12,7 +12,7 @@ BEGIN {
276c98
 
276c98
 use warnings;
276c98
 
276c98
-plan(tests => 276 );
276c98
+plan(tests => 277 );
276c98
 
276c98
 # type coercion on assignment
276c98
 $foo = 'foo';
276c98
@@ -1153,6 +1153,22 @@ pass "No crash due to CvGV pointing to glob copy in the stash";
276c98
     is($c_125840, 1, 'RT #125840: $c=$d');
276c98
 }
276c98
 
276c98
+# [perl #128597] Crash when gp_free calls ckWARN_d
276c98
+# I am not sure this test even belongs in this file, as the crash was the
276c98
+# result of various features interacting.  But a call to ckWARN_d from
276c98
+# gv.c:gp_free triggered the crash, so this seems as good a place as any.
276c98
+# ‘die’ (or any abnormal scope exit) can cause the current cop to be freed,
276c98
+# if the subroutine containing the ‘die’ gets freed as a result.  That
276c98
+# causes PL_curcop to be set to NULL.  If a writable handle gets freed
276c98
+# while PL_curcop is NULL, then gp_free will call ckWARN_d while that con-
276c98
+# dition still holds, so ckWARN_d needs to know about PL_curcop possibly
276c98
+# being NULL.
276c98
+SKIP: {
276c98
+    skip_if_miniperl("No PerlIO::scalar on miniperl", 1);
276c98
+    runperl(prog => 'open my $fh, q|>|, \$buf;'
276c98
+                   .'my $sub = eval q|sub {exit 0}|; $sub->()');
276c98
+    is ($? & 127, 0,"[perl #128597] No crash when gp_free calls ckWARN_d");
276c98
+}
276c98
 
276c98
 __END__
276c98
 Perl
276c98
diff --git a/warnings.h b/warnings.h
276c98
index 337bef3..4d13732 100644
276c98
--- a/warnings.h
276c98
+++ b/warnings.h
276c98
@@ -115,8 +115,10 @@
276c98
 #define WARN_ALLstring			 "\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125"
276c98
 #define WARN_NONEstring			 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
276c98
 
276c98
-#define isLEXWARN_on 	cBOOL(PL_curcop->cop_warnings != pWARN_STD)
276c98
-#define isLEXWARN_off	cBOOL(PL_curcop->cop_warnings == pWARN_STD)
276c98
+#define isLEXWARN_on \
276c98
+	cBOOL(PL_curcop && PL_curcop->cop_warnings != pWARN_STD)
276c98
+#define isLEXWARN_off \
276c98
+	cBOOL(!PL_curcop || PL_curcop->cop_warnings == pWARN_STD)
276c98
 #define isWARN_ONCE	(PL_dowarn & (G_WARN_ON|G_WARN_ONCE))
276c98
 #define isWARN_on(c,x)	(IsSet((U8 *)(c + 1), 2*(x)))
276c98
 #define isWARNf_on(c,x)	(IsSet((U8 *)(c + 1), 2*(x)+1))
276c98
-- 
276c98
2.5.5
276c98