php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45181 chdir() should clear relative entries in stat cache
Submitted: 2008-06-04 18:54 UTC Modified: 2008-08-11 22:44 UTC
From: webmaster at villagersonline dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID:
 [2008-06-04 18:54 UTC] webmaster at villagersonline dot com
Description:
------------
If you check a relative pathname with is_dir(), the result is cached.  However, chdir() does not invalidate that cache.  Thus, after a chdir(), is_dir() using the same relative pathname gives invalid results.

NOTE: In truth, I'm running PHP 5.2.5, not 5.2.6.  But this is on a professional hosting service, and I can't control the version.

Reproduce code:
---------------
<?
   // note that if you run this script multiple times, then all the
   // mkdir()s will give errors, since they already exist.  That's
   // irrelevant to the bug.

   // I put this all inside a subdirectory so as to not clutter up the
   // pwd of the script.  Again, irrelevant to the bug.
   mkdir("x");
   chdir("x");
      clearstatcache();

   // key reproduce code starts here
   mkdir("y");
   mkdir("z");

   var_dump(is_dir("z"));

   chdir("y");
   var_dump(is_dir("z"));    // this is where the bug is exposed
   var_dump(is_dir(getcwd()."/z"));

   clearstatcache();
   var_dump(is_dir("z"));
?>

Expected result:
----------------
bool(true)
bool(false)
bool(false)
bool(false)

Actual result:
--------------
bool(true)
bool(true)
bool(false)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-11 22:44 UTC] lbarnaud@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 10:02:06 2014 UTC