OSDN Git Service

BugTrack2/236: Care for readdir() returns FALSE
authorhenoheno <henoheno>
Sat, 3 Nov 2007 15:17:52 +0000 (00:17 +0900)
committerumorigu <umorigu@gmail.com>
Sun, 30 Nov 2014 03:56:52 +0000 (12:56 +0900)
lib/file.php
plugin/attach.inc.php
plugin/dump.inc.php

index 400c204..979cb5c 100644 (file)
@@ -510,21 +510,36 @@ function header_lastmod($page = NULL)
        }
 }
 
+// Get a list of encoded files (must specify a directory and a suffix)
+function get_existfiles($dir = DATA_DIR, $ext = '.txt')
+{
+       $aryret = array();
+       $pattern = '/^(?:[0-9A-F]{2})+' . preg_quote($ext, '/') . '$/';
+
+       $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.');
+       while (($file = readdir($dp)) !== FALSE) {
+               if (preg_match($pattern, $file)) {
+                       $aryret[] = $dir . $file;
+               }
+       }
+       closedir($dp);
+
+       return $aryret;
+}
+
 // Get a page list of this wiki
 function get_existpages($dir = DATA_DIR, $ext = '.txt')
 {
        $aryret = array();
+       $pattern = '/^((?:[0-9A-F]{2})+)' . preg_quote($ext, '/') . '$/';
 
-       $pattern = '((?:[0-9A-F]{2})+)';
-       if ($ext != '') $ext = preg_quote($ext, '/');
-       $pattern = '/^' . $pattern . $ext . '$/';
-
-       $dp = @opendir($dir) or
-               die_message($dir . ' is not found or not readable.');
+       $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.');
        $matches = array();
-       while ($file = readdir($dp))
-               if (preg_match($pattern, $file, $matches))
+       while (($file = readdir($dp)) !== FALSE) {
+               if (preg_match($pattern, $file, $matches)) {
                        $aryret[$file] = decode($matches[1]);
+               }
+       }
        closedir($dp);
 
        return $aryret;
@@ -691,19 +706,6 @@ function get_readings()
        return $readings;
 }
 
-// Get a list of encoded files (must specify a directory and a suffix)
-function get_existfiles($dir, $ext)
-{
-       $pattern = '/^(?:[0-9A-F]{2})+' . preg_quote($ext, '/') . '$/';
-       $aryret = array();
-       $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.');
-       while ($file = readdir($dp))
-               if (preg_match($pattern, $file))
-                       $aryret[] = $dir . $file;
-       closedir($dp);
-       return $aryret;
-}
-
 // Get a list of related pages of the page
 function links_get_related($page)
 {
index 7fda592..bdbcb75 100644 (file)
@@ -818,9 +818,8 @@ class AttachPages
                $pattern = "/^({$page_pattern})_((?:[0-9A-F]{2})+){$age_pattern}$/";
 
                $matches = array();
-               while ($file = readdir($dir)) {
-                       if (! preg_match($pattern, $file, $matches))
-                               continue;
+               while (($file = readdir($dir)) !== FALSE) {
+                       if (! preg_match($pattern, $file, $matches)) continue;
 
                        $_page = decode($matches[1]);
                        $_file = decode($matches[2]);
index c8a54f7..763c144 100644 (file)
@@ -1,5 +1,9 @@
 <?php
-// $Id: dump.inc.php,v 1.38 2007/05/12 09:17:14 henoheno Exp $
+// $Id: dump.inc.php,v 1.41 2007/11/03 15:17:52 henoheno Exp $
+// Copyright (C)
+//   2004-2007 PukiWiki Developers Team
+//   2004      teanan / Interfair Laboratory
+// License: GPL v2 or (at your option) any later version
 //
 // Remote dump / restore plugin
 // Originated as tarfile.inc.php by teanan / Interfair Laboratory 2004.
@@ -386,10 +390,10 @@ class tarlib
                        @unlink($this->filename);
                        die_message($dir . ' is not found or not readable.');
                }
-
-               while ($filename = readdir($dp)) {
-                       if (preg_match("/$mask/", $filename))
+               while (($filename = readdir($dp)) !== FALSE) {
+                       if (preg_match('/' . $mask . '/', $filename)) {
                                $files[] = $dir . $filename;
+                       }
                }
                closedir($dp);