Blame SOURCES/perl-5.25.2-SEGV-in-Subroutine-redefined-warning.patch

276c98
From fc0fe26a7d286480c1bb25f57e469ece575bb68d Mon Sep 17 00:00:00 2001
276c98
From: David Mitchell <davem@iabyn.com>
276c98
Date: Thu, 7 Jul 2016 17:03:29 +0100
276c98
Subject: [PATCH] SEGV in "Subroutine redefined" warning
276c98
MIME-Version: 1.0
276c98
Content-Type: text/plain; charset=UTF-8
276c98
Content-Transfer-Encoding: 8bit
276c98
276c98
RT #128257
276c98
276c98
The following SEGVed:
276c98
276c98
    sub P::f{}
276c98
    undef *P::;
276c98
    *P::f =sub{};
276c98
276c98
due to the code which generates the "Subroutine STASH::NAME redefined"
276c98
warning assuming that the GV always has a stash. Make it so that if it
276c98
hasn't, the message changes to  "Subroutine NAME redefined" rather than
276c98
just crashing.
276c98
276c98
Signed-off-by: Petr Písař <ppisar@redhat.com>
276c98
---
276c98
 sv.c              | 18 +++++++++++-------
276c98
 t/lib/warnings/sv |  8 ++++++++
276c98
 2 files changed, 19 insertions(+), 7 deletions(-)
276c98
276c98
diff --git a/sv.c b/sv.c
276c98
index 1b7a283..0cbe371 100644
276c98
--- a/sv.c
276c98
+++ b/sv.c
276c98
@@ -4074,14 +4074,18 @@ Perl_gv_setref(pTHX_ SV *const dstr, SV *const sstr)
276c98
 			    CvCONST((const CV *)sref)
276c98
 				 ? cv_const_sv((const CV *)sref)
276c98
 				 : NULL;
276c98
+                        HV * const stash = GvSTASH((const GV *)dstr);
276c98
 			report_redefined_cv(
276c98
-			   sv_2mortal(Perl_newSVpvf(aTHX_
276c98
-				"%"HEKf"::%"HEKf,
276c98
-				HEKfARG(
276c98
-				 HvNAME_HEK(GvSTASH((const GV *)dstr))
276c98
-				),
276c98
-				HEKfARG(GvENAME_HEK(MUTABLE_GV(dstr)))
276c98
-			   )),
276c98
+			   sv_2mortal(
276c98
+                             stash
276c98
+                               ? Perl_newSVpvf(aTHX_
276c98
+				    "%"HEKf"::%"HEKf,
276c98
+				    HEKfARG(HvNAME_HEK(stash)),
276c98
+				    HEKfARG(GvENAME_HEK(MUTABLE_GV(dstr))))
276c98
+                               : Perl_newSVpvf(aTHX_
276c98
+				    "%"HEKf,
276c98
+				    HEKfARG(GvENAME_HEK(MUTABLE_GV(dstr))))
276c98
+			   ),
276c98
 			   cv,
276c98
 			   CvCONST((const CV *)sref) ? &new_const_sv : NULL
276c98
 			);
276c98
diff --git a/t/lib/warnings/sv b/t/lib/warnings/sv
276c98
index 5ddd4fe..c8e0e62 100644
276c98
--- a/t/lib/warnings/sv
276c98
+++ b/t/lib/warnings/sv
276c98
@@ -413,3 +413,11 @@ Argument "a_c" isn't numeric in preincrement (++) at - line 5.
276c98
 Argument "(?^:abc)" isn't numeric in preincrement (++) at - line 6.
276c98
 Argument "123x" isn't numeric in preincrement (++) at - line 7.
276c98
 Argument "123e" isn't numeric in preincrement (++) at - line 8.
276c98
+########
276c98
+# RT #128257 This used to SEGV
276c98
+use warnings;
276c98
+sub Foo::f {}
276c98
+undef *Foo::;
276c98
+*Foo::f =sub {};
276c98
+EXPECT
276c98
+Subroutine f redefined at - line 5.
276c98
-- 
276c98
2.5.5
276c98