From 7274b33cb1232fb4911cb441bae8e0abebf734f2 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sun, 3 Nov 2013 04:47:17 -0800 Subject: [PATCH] =?utf8?q?=EF=BD=93=EF=BD=95=EF=BD=82=E3=80=80=EF=BC=AE?= =?utf8?q?=EF=BC=A5=EF=BC=A7=EF=BC=A1=EF=BC=B4=EF=BC=A9=EF=BC=B6=EF=BC=A5?= =?utf8?q?=EF=BC=BF=EF=BC=A9=EF=BC=AE=EF=BC=A4=EF=BC=A9=EF=BC=A3=EF=BC=A5?= =?utf8?q?=EF=BC=B3=EF=BC=9B=20+=20=EF=BC=84=EF=BD=94=EF=BD=89=EF=BD=85?= =?utf8?q?=EF=BD=84=EF=BC=BB=EF=BC=8D=EF=BC=91=EF=BC=BD=20=3D=20crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This code in av.c, when trying to find $NEGATIVE_INDICES, was doing a direct stash element lookup--instead of going through the normal GV functions--and then expecting the returned value to be a GV. ‘sub NEGATIVE_INDICES’ creates a stash element that is a PV, not a GV, so it’s easy to make things crash. --- av.c | 3 ++- t/op/tie.t | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/av.c b/av.c index 3473d08..2a8ccf0 100644 --- a/av.c +++ b/av.c @@ -201,7 +201,8 @@ S_adjust_index(pTHX_ AV *av, const MAGIC *mg, SSize_t *keyp) SV * const * const negative_indices_glob = hv_fetchs(SvSTASH(SvRV(ref)), NEGATIVE_INDICES_VAR, 0); - if (negative_indices_glob && SvTRUE(GvSV(*negative_indices_glob))) + if (negative_indices_glob && isGV(*negative_indices_glob) + && SvTRUE(GvSV(*negative_indices_glob))) adjust_index = 0; } } diff --git a/t/op/tie.t b/t/op/tie.t index d6e641e..e0b2499 100644 --- a/t/op/tie.t +++ b/t/op/tie.t @@ -1341,6 +1341,16 @@ Can't call method "FETCHSIZE" on an undefined value at - line 7. Can't call method "FETCHSIZE" on an undefined value at - line 8. ######## +# Crash when reading negative index when NEGATIVE_INDICES stub exists +sub NEGATIVE_INDICES; +sub TIEARRAY{bless[]}; +sub FETCHSIZE{} +tie @a, ""; +print "ok\n" if ! defined $a[-1]; +EXPECT +ok +######## + # Assigning vstrings to tied scalars sub TIESCALAR{bless[]}; sub STORE { print ref \$_[1], "\n" } -- 2.7.4