dcb3b7
From cba9aa759f7ce8a4a80e748eb451f679042cd74b Mon Sep 17 00:00:00 2001
dcb3b7
From: Father Chrysostomos <sprout@cpan.org>
dcb3b7
Date: Fri, 7 Apr 2017 14:08:02 -0700
dcb3b7
Subject: [PATCH] Crash with sub-in-stash
dcb3b7
MIME-Version: 1.0
dcb3b7
Content-Type: text/plain; charset=UTF-8
dcb3b7
Content-Transfer-Encoding: 8bit
dcb3b7
dcb3b7
Ported to 5.24.1:
dcb3b7
dcb3b7
commit 790acddeaa0d2c73524596048b129561225cf100
dcb3b7
Author: Father Chrysostomos <sprout@cpan.org>
dcb3b7
Date:   Fri Apr 7 14:08:02 2017 -0700
dcb3b7
dcb3b7
    [perl #131085] Crash with sub-in-stash
dcb3b7
dcb3b7
    $ perl -e '$::{"A"} = sub {}; \&{"A"}'
dcb3b7
    Segmentation fault (core dumped)
dcb3b7
dcb3b7
    The code that vivifies a typeglob out of a code ref assumed that the
dcb3b7
    CV had a name hek, which is always the case when perl itself puts the
dcb3b7
    code ref there (via ‘sub A{}’), but is not necessarily the case if
dcb3b7
    someone is insinuating other stuff into the stash.
dcb3b7
dcb3b7
Signed-off-by: Petr Písař <ppisar@redhat.com>
dcb3b7
---
dcb3b7
 gv.c      | 2 +-
dcb3b7
 t/op/gv.t | 4 ++++
dcb3b7
 2 files changed, 5 insertions(+), 1 deletion(-)
dcb3b7
dcb3b7
diff --git a/gv.c b/gv.c
dcb3b7
index 3fda9b9..6690b64 100644
dcb3b7
--- a/gv.c
dcb3b7
+++ b/gv.c
dcb3b7
@@ -421,7 +421,7 @@ Perl_gv_init_pvn(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, U32 flag
dcb3b7
 	/* Not actually a constant.  Just a regular sub.  */
dcb3b7
 	CV * const cv = (CV *)has_constant;
dcb3b7
 	GvCV_set(gv,cv);
dcb3b7
-	if (CvSTASH(cv) == stash && (
dcb3b7
+	if (CvNAMED(cv) && CvSTASH(cv) == stash && (
dcb3b7
 	       CvNAME_HEK(cv) == GvNAME_HEK(gv)
dcb3b7
 	    || (  HEK_LEN(CvNAME_HEK(cv)) == HEK_LEN(GvNAME_HEK(gv))
dcb3b7
 	       && HEK_FLAGS(CvNAME_HEK(cv)) != HEK_FLAGS(GvNAME_HEK(gv))
dcb3b7
diff --git a/t/op/gv.t b/t/op/gv.t
dcb3b7
index 03ae46e..cdaaef5 100644
dcb3b7
--- a/t/op/gv.t
dcb3b7
+++ b/t/op/gv.t
dcb3b7
@@ -1170,6 +1170,10 @@ SKIP: {
dcb3b7
     is ($? & 127, 0,"[perl #128597] No crash when gp_free calls ckWARN_d");
dcb3b7
 }
dcb3b7
 
dcb3b7
+# [perl #131085] This used to crash; no ok() necessary.
dcb3b7
+$::{"A131085"} = sub {}; \&{"A131085"};
dcb3b7
+
dcb3b7
+
dcb3b7
 __END__
dcb3b7
 Perl
dcb3b7
 Rules
dcb3b7
-- 
dcb3b7
2.9.4
dcb3b7