This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #126162) warn if stat() is called on an array
authorDan Collins <dcollinsn@gmail.com>
Wed, 30 Mar 2016 05:42:39 +0000 (16:42 +1100)
committerRicardo Signes <rjbs@cpan.org>
Thu, 7 Apr 2016 11:45:08 +0000 (07:45 -0400)
op.c
t/op/stat.t

diff --git a/op.c b/op.c
index e58f711..9bbe4f3 100644 (file)
--- a/op.c
+++ b/op.c
@@ -9733,6 +9733,10 @@ Perl_ck_ftst(pTHX_ OP *o)
            op_free(o);
            return newop;
        }
+
+       if (kidtype == OP_RV2AV) {
+           Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Array passed to stat will be coerced to a scalar (did you want stat $_[0]?)");
+       }
        scalar((OP *) kid);
        if ((PL_hints & HINT_FILETEST_ACCESS) && OP_IS_FILETEST_ACCESS(o->op_type))
            o->op_private |= OPpFT_ACCESS;
index 2d7e3c7..c388083 100644 (file)
@@ -25,7 +25,7 @@ if ($^O eq 'MSWin32') {
     ${^WIN32_SLOPPY_STAT} = 0;
 }
 
-plan tests => 116;
+plan tests => 118;
 
 my $Perl = which_perl();
 
@@ -636,6 +636,14 @@ SKIP: {
 is join("-", 1,2,3,(stat stat stat),4,5,6), "1-2-3-4-5-6",
   'stat inside stat gets scalar context';
 
+# [perl #126162] stat an array should not work
+my $statfile = './op/stat.t';
+my @statarg = ($statfile, $statfile);
+ok !stat(@statarg),
+  'stat on an array of valid paths should warn and should not return any data';
+is $!, 'No such file or directory',
+  'stat on an array of valid paths should return "No such file or directory"';
+
 END {
     chmod 0666, $tmpfile;
     unlink_all $tmpfile;