From: Peter Dintelmann Date: Wed, 8 Feb 2006 01:33:54 +0000 (-0800) Subject: [perl #38464] chdir() on closed handles X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4dc171f099f09ddce664c46adaa55908b398396f;p=p5sagit%2Fp5-mst-13.2.git [perl #38464] chdir() on closed handles From: Peter Dintelmann (via RT) Message-ID: Plus a regression test. p4raw-id: //depot/perl@27130 --- diff --git a/pp_sys.c b/pp_sys.c index 8e8004a..5437c62 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -3345,10 +3345,16 @@ PP(pp_chdir) #endif } else { + if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) + report_evil_fh(gv, io, PL_op->op_type); + SETERRNO(EBADF, RMS_IFI); PUSHi(0); } } else { + if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) + report_evil_fh(gv, io, PL_op->op_type); + SETERRNO(EBADF,RMS_IFI); PUSHi(0); } #else diff --git a/t/lib/warnings/pp_sys b/t/lib/warnings/pp_sys index d84ff75..4149117 100644 --- a/t/lib/warnings/pp_sys +++ b/t/lib/warnings/pp_sys @@ -457,3 +457,22 @@ no warnings 'misc'; select $x, undef, undef, undef; EXPECT Non-string passed as bitmask at - line 4. +######## +opendir FOO, '.'; closedir FOO; +open BAR, '.'; close BAR; +opendir $dh, '.'; closedir $dh; +open $fh, '.'; close $fh; +chdir FOO; +chdir BAR; +chdir $dh; +chdir $fh; +use warnings qw(unopened closed) ; +chdir FOO; +chdir BAR; +chdir $dh; +chdir $fh; +EXPECT +chdir() on unopened filehandle FOO at - line 10. +chdir() on closed filehandle BAR at - line 11. +chdir() on unopened filehandle $dh at - line 12. +chdir() on closed filehandle $fh at - line 13.