Check that stash entries are GVs when aliasing pkgs
authorFather Chrysostomos <sprout@cpan.org>
Sun, 3 Nov 2013 13:49:48 +0000 (05:49 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 4 Nov 2013 13:10:18 +0000 (05:10 -0800)
$ perl5.18.1 -e '$Foo::{"Bar::"} = 0; $Bar::Bar::; *Bar:: = *Foo::'
Segmentation fault: 11

That $Foo::{"Bar::"} = 0; assignment is documented as having unde-
fined behaviour, but it shouldn’t crash.

mro.c
t/mro/package_aliases.t

diff --git a/mro.c b/mro.c
index 18dfa8c..04b3c27 100644 (file)
--- a/mro.c
+++ b/mro.c
@@ -1151,7 +1151,7 @@ S_mro_gather_and_rename(pTHX_ HV * const stashes, HV * const seen_stashes,
 
                    if(
                        (
-                           stashentry && *stashentry
+                           stashentry && *stashentry && isGV(*stashentry)
                         && (substash = GvHV(*stashentry))
                        )
                     || (oldsubstash && HvENAME_get(oldsubstash))
index 34aa2d6..6998a89 100644 (file)
@@ -10,7 +10,7 @@ BEGIN {
 
 use strict;
 use warnings;
-plan(tests => 53);
+plan(tests => 54);
 
 {
     package New;
@@ -408,3 +408,11 @@ local *Fooo:: = \%Baro::;
     no warnings;
     is 'Bazo'->ber, 'black sheep', 'localised *glob=$stashref assignment';
 }
+
+# $Stash::{"entries::"} that are not globs.
+# These used to crash.
+$NotGlob::{"NotGlob::"} = 0; () = $NewNotGlob::NotGlob::;
+*NewNotGlob:: = *NotGlob::;
+pass(
+   "no crash when clobbering sub-'stash' whose parent stash entry is no GV"
+);