This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t call get-magic on a referenced array in chdir, etc.
authorFather Chrysostomos <sprout@cpan.org>
Sat, 10 Sep 2011 17:01:00 +0000 (10:01 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 10 Sep 2011 20:46:59 +0000 (13:46 -0700)
Commit 557fbd17eb added the MAYBE_DEREF_GV macro, which 2ea1cce
applied to chdir, chmod and chown.

That macro calls get-magic on its arguments checks to see if it might
be a gv or ref and, if it’s a ref, calls get-magic on the referent,
to see whether it will turn into a gv.  That means we’ll end up with
chdir($array_obj) calling get-magic on the array.  While probably
harmless, calling get-magic is superfluous and probably incorrect.  I
don’t know that there is a reasonable way to test this.

pp.h

diff --git a/pp.h b/pp.h
index b6798ea..23636cc 100644 (file)
--- a/pp.h
+++ b/pp.h
@@ -510,7 +510,8 @@ True if this op will be the return value of an lvalue subroutine
        SvGETMAGIC(sv),                                              \
        isGV_with_GP(sv)                                              \
          ? (GV *)sv                                                   \
-         : SvROK(sv) && (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv))) \
+         : SvROK(sv) && SvTYPE(SvRV(sv)) <= SVt_PVLV &&               \
+           (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv)))              \
             ? (GV *)SvRV(sv)                                            \
             : NULL                                                       \
     )