php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24048 opendir() drop the previous directory pointer
Submitted: 2003-06-05 13:51 UTC Modified: 2003-06-05 14:03 UTC
From: mrgibson at golum dot net Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 4.3.2 OS: windows 2000
Private report: No CVE-ID: None
 [2003-06-05 13:51 UTC] mrgibson at golum dot net
Im running the code as a CLI application, i don't know if the bug persist with the PHP module or CGI.

This is a little script that show the problem:

<?php

 function recurse_search($dir,$pattern)
          {     
          stdout_write("Recurse_search $dir,$pattern");
          $temp = "";
          $len = strlen($pattern);
          $d = @opendir($dir);
          if (!$d) die("Directory $dir not mounted or unavailable");
          clearstatcache();
          while($file = readdir($d))
                {
                
                if ($temp != "") break;
                
                if ($file[0]==".") continue;
                if ($file[0]=="#") continue;
                
                stdout_write($file);
                if (is_dir($dir.$file."/"))
                                {
                                stdout_write("DIR : $file");
                        	$bof =  recurse_search($dir.$file."/",$pattern);
                                }
                                else
                                    if (substr($file,0,$len)==$pattern) 
                                    			{
                                    				close($d);
                                    				die($dir.$file);
                                    				return $dir.$file;
                                    			}

                  
                }
          closedir($d);
          return $temp;
          }
    }

  function stdout_write($content)
      {
      $fp = fopen("php://stdout","w");
      fwrite($content."\r\n");
      fclose($fp);
      }

print recurse_search("c:\\","system.ini");
?>
----------------------------------------------------
When i get back from a prior directory recursion, the
$file = readdir($d) stop working and the function exit.





Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-05 13:54 UTC] mrgibson at golum dot net
A little error:
replace $bof by $temp 

and if ($file[0]=="#") continue;
is unnessesary
 [2003-06-05 13:59 UTC] mrgibson at golum dot net
forget, its my fault not php.
 [2003-06-05 14:03 UTC] philip@php.net
status->bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 20:01:27 2024 UTC