dcb3b7
From 63aab7ecaa6e826f845c405894bd8c4b6f601b39 Mon Sep 17 00:00:00 2001
dcb3b7
From: Father Chrysostomos <sprout@cpan.org>
dcb3b7
Date: Sun, 3 Jul 2016 22:23:34 -0700
dcb3b7
Subject: [PATCH] [perl #128532] Crash vivifying stub in deleted pkg
dcb3b7
MIME-Version: 1.0
dcb3b7
Content-Type: text/plain; charset=UTF-8
dcb3b7
Content-Transfer-Encoding: 8bit
dcb3b7
dcb3b7
v5.17.0-515-g186a5ba, which added newSTUB, did not take into account
dcb3b7
that a GV may have a null GvSTASH pointer, if its stash has been
dcb3b7
freed, so this crashes:
dcb3b7
dcb3b7
delete $My::{"Foo::"}; \&My::Foo::foo
dcb3b7
dcb3b7
Signed-off-by: Petr Písař <ppisar@redhat.com>
dcb3b7
---
dcb3b7
 op.c       | 2 +-
dcb3b7
 t/op/ref.t | 6 +++++-
dcb3b7
 2 files changed, 6 insertions(+), 2 deletions(-)
dcb3b7
dcb3b7
diff --git a/op.c b/op.c
dcb3b7
index 46e76ac..4735d1b 100644
dcb3b7
--- a/op.c
dcb3b7
+++ b/op.c
dcb3b7
@@ -9081,7 +9081,7 @@ Perl_newSTUB(pTHX_ GV *gv, bool fake)
dcb3b7
     assert(!GvCVu(gv));
dcb3b7
     GvCV_set(gv, cv);
dcb3b7
     GvCVGEN(gv) = 0;
dcb3b7
-    if (!fake && HvENAME_HEK(GvSTASH(gv)))
dcb3b7
+    if (!fake && GvSTASH(gv) && HvENAME_HEK(GvSTASH(gv)))
dcb3b7
 	gv_method_changed(gv);
dcb3b7
     if (SvFAKE(gv)) {
dcb3b7
 	cvgv = gv_fetchsv((SV *)gv, GV_ADDMULTI, SVt_PVCV);
dcb3b7
diff --git a/t/op/ref.t b/t/op/ref.t
dcb3b7
index 19a44bb..84d9217 100644
dcb3b7
--- a/t/op/ref.t
dcb3b7
+++ b/t/op/ref.t
dcb3b7
@@ -8,7 +8,7 @@ BEGIN {
dcb3b7
 
dcb3b7
 use strict qw(refs subs);
dcb3b7
 
dcb3b7
-plan(235);
dcb3b7
+plan(236);
dcb3b7
 
dcb3b7
 # Test this first before we extend the stack with other operations.
dcb3b7
 # This caused an asan failure due to a bad write past the end of the stack.
dcb3b7
@@ -124,6 +124,10 @@ is (join(':',@{$spring2{"foo"}}), "1:2:3:4");
dcb3b7
     is ($called, 1);
dcb3b7
 }
dcb3b7
 is ref eval {\&{""}}, "CODE", 'reference to &{""} [perl #94476]';
dcb3b7
+delete $My::{"Foo::"}; 
dcb3b7
+is ref \&My::Foo::foo, "CODE",
dcb3b7
+  'creating stub with \&deleted_stash::foo [perl #128532]';
dcb3b7
+
dcb3b7
 
dcb3b7
 # Test references to return values of operators (TARGs/PADTMPs)
dcb3b7
 {
dcb3b7
-- 
dcb3b7
2.5.5
dcb3b7