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