b8c914
From cb2fda94b02c5b7e8d16582410034f5a3dae526f Mon Sep 17 00:00:00 2001
b8c914
From: Tony Cook <tony@develop-help.com>
b8c914
Date: Tue, 25 Jul 2017 16:21:22 +1000
b8c914
Subject: [PATCH] (perl #131588) be a little more careful in arybase::_tie_it()
b8c914
MIME-Version: 1.0
b8c914
Content-Type: text/plain; charset=UTF-8
b8c914
Content-Transfer-Encoding: 8bit
b8c914
b8c914
Original patch by John Leitch <john@autosectools.com>
b8c914
Petr Pisar: Ported to 5.26.0.
b8c914
b8c914
Signed-off-by: Petr Písař <ppisar@redhat.com>
b8c914
---
b8c914
 ext/arybase/arybase.xs  | 10 ++++++----
b8c914
 ext/arybase/t/arybase.t |  4 +++-
b8c914
 2 files changed, 9 insertions(+), 5 deletions(-)
b8c914
b8c914
diff --git a/ext/arybase/arybase.xs b/ext/arybase/arybase.xs
b8c914
index 880bbe3..216442a 100644
b8c914
--- a/ext/arybase/arybase.xs
b8c914
+++ b/ext/arybase/arybase.xs
b8c914
@@ -438,10 +438,12 @@ _tie_it(SV *sv)
b8c914
     INIT:
b8c914
 	GV * const gv = (GV *)sv;
b8c914
     CODE:
b8c914
-	if (GvSV(gv))
b8c914
-	    /* This is *our* scalar now!  */
b8c914
-	    sv_unmagic(GvSV(gv), PERL_MAGIC_sv);
b8c914
-	tie(aTHX_ GvSVn(gv), NULL, GvSTASH(CvGV(cv)));
b8c914
+	if (isGV(gv)) {
b8c914
+	    if (GvSV(gv))
b8c914
+	        /* This is *our* scalar now!  */
b8c914
+	        sv_unmagic(GvSV(gv), PERL_MAGIC_sv);
b8c914
+	    tie(aTHX_ GvSVn(gv), NULL, GvSTASH(CvGV(cv)));
b8c914
+	}
b8c914
 
b8c914
 void
b8c914
 FETCH(...)
b8c914
diff --git a/ext/arybase/t/arybase.t b/ext/arybase/t/arybase.t
b8c914
index f3d3287..41e90df 100644
b8c914
--- a/ext/arybase/t/arybase.t
b8c914
+++ b/ext/arybase/t/arybase.t
b8c914
@@ -4,7 +4,7 @@
b8c914
 # plus miscellaneous bug fix tests
b8c914
 
b8c914
 no warnings 'deprecated';
b8c914
-use Test::More tests => 7;
b8c914
+use Test::More tests => 8;
b8c914
 
b8c914
 sub outside_base_scope { return "${'['}" }
b8c914
 
b8c914
@@ -34,4 +34,6 @@ is $@, "That use of \$[ is unsupported at $f line $l.\n",
b8c914
 
b8c914
 sub foo { my $x; $x = wait } # compilation of this routine used to crash
b8c914
 
b8c914
+ok eval { arybase::_tie_it(1); 1 }, "don't crash on bad call to _tie_it()";
b8c914
+
b8c914
 1;
b8c914
-- 
b8c914
2.9.4
b8c914