#44246 [NEW]: closedir() accepts a file resource opened by fopen()
| From: | jmessa@php.net | Date: | Mon, 25 Feb 2008 16:55:39 +0000 |
| Subject: | #44246 [NEW]: closedir() accepts a file resource opened by fopen() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-122691@lists.php.net to get a copy of this message | ||
From: jmessa@php.net
Operating system: Windows XP
PHP version: 5.2CVS-2008-02-25 (CVS)
PHP Bug Type: *Directory/Filesystem functions
Bug description: closedir() accepts a file resource opened by fopen()
Description:
------------
closedir() will accept a file resource opened by fopen() as the $directory
argument. In the documentation for closedir() it says the following: "The
stream must have previously been opened by opendir()". It seems that the
resource type is not being checked correctly.
A directory opened with opendir() can also be passed to fclose() without
an error message being generated.
Reproduce code:
---------------
<?php
var_dump($fp = fopen(__FILE__, 'r'));
closedir($fp);
var_dump($fp);
$directory = dirname(__FILE__) . '/test';
mkdir($directory);
var_dump($dh = opendir($directory));
var_dump(fclose($dh));
var_dump($dh);
?>
Expected result:
----------------
resource(5) of type (stream)
Warning: closedir(): supplied argument is not a valid Directory resource
in ...
resource(5) of type (stream)
resource(6) of type (stream)
Warning: fclose(): supplied argument is not a valid stream resource in
...
bool(false)
resource(6) of type (stream)
Actual result:
--------------
resource(5) of type (stream)
resource(5) of type (Unknown)
resource(6) of type (stream)
bool(true)
resource(6) of type (stream)
--
Edit bug report at http://bugs.php.net/?id=44246&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44246&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44246&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44246&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44246&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=44246&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44246&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44246&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44246&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44246&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44246&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=44246&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=44246&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44246&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44246&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44246&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44246&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44246&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44246&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44246&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44246&r=mysqlcfg