In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/8334cae656b5c7fd6ff3536633897332d0ee089a?hp=5df244132ec94f1e67bd70db61d4ea89bd824b00>
- Log ----------------------------------------------------------------- commit 8334cae656b5c7fd6ff3536633897332d0ee089a Author: Tony Cook <[email protected]> Date: Wed Oct 22 16:20:08 2014 +1100 [perl #122703] ensure $! is set when chmod() and utime() fail When called with a closed file handle, neither chmod nor utime set errno when they failed, chown() did set errno, but this wasn't tested. ----------------------------------------------------------------------- Summary of changes: doio.c | 2 ++ t/io/fs.t | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/doio.c b/doio.c index c7aceca..1f5f932 100644 --- a/doio.c +++ b/doio.c @@ -1762,6 +1762,7 @@ Perl_apply(pTHX_ I32 type, SV **mark, SV **sp) #endif } else { + SETERRNO(EBADF,RMS_IFI); tot--; } } @@ -1802,6 +1803,7 @@ Perl_apply(pTHX_ I32 type, SV **mark, SV **sp) #endif } else { + SETERRNO(EBADF,RMS_IFI); tot--; } } diff --git a/t/io/fs.t b/t/io/fs.t index 628a2ca..9b41e65 100644 --- a/t/io/fs.t +++ b/t/io/fs.t @@ -56,7 +56,7 @@ $needs_fh_reopen = 1 if (defined &Win32::IsWin95 && Win32::IsWin95()); my $skip_mode_checks = $^O eq 'cygwin' && $ENV{CYGWIN} !~ /ntsec/; -plan tests => 55; +plan tests => 61; my $tmpdir = tempfile(); my $tmpdir1 = tempfile(); @@ -180,7 +180,7 @@ SKIP: { } SKIP: { - skip "no fchmod", 5 unless ($Config{d_fchmod} || "") eq "define"; + skip "no fchmod", 7 unless ($Config{d_fchmod} || "") eq "define"; ok(open(my $fh, "<", "a"), "open a"); is(chmod(0, $fh), 1, "fchmod"); $mode = (stat "a")[2]; @@ -194,12 +194,26 @@ SKIP: { skip "no mode checks", 1 if $skip_mode_checks; is($mode & 0777, $newmode, "perm restored"); } + + # [perl #122703] + close $fh; + $! = 0; + ok(!chmod(0666, $fh), "chmod through closed handle fails"); + isnt($!+0, 0, "and errno was set"); } SKIP: { - skip "no fchown", 1 unless ($Config{d_fchown} || "") eq "define"; + skip "no fchown", 3 unless ($Config{d_fchown} || "") eq "define"; open(my $fh, "<", "a"); is(chown(-1, -1, $fh), 1, "fchown"); + + # [perl #122703] + # chown() behaved correctly, but there was no test for the chown() + # on closed handle case + close $fh; + $! = 0; + ok(!chown(-1, -1, $fh), "chown on closed handle fails"); + isnt($!+0, 0, "and errno was set"); } SKIP: { @@ -237,11 +251,16 @@ isnt($atime, 500000000, 'atime'); isnt($mtime, 500000000 + $delta, 'mtime'); SKIP: { - skip "no futimes", 4 unless ($Config{d_futimes} || "") eq "define"; + skip "no futimes", 6 unless ($Config{d_futimes} || "") eq "define"; open(my $fh, "<", 'b'); $foo = (utime 500000000,500000000 + $delta, $fh); is($foo, 1, "futime"); check_utime_result(); + # [perl #122703] + close $fh; + ok(!utime(500000000,500000000 + $delta, $fh), + "utime fails on a closed file handle"); + isnt($!+0, 0, "and errno was set"); } -- Perl5 Master Repository
