From 4dfc61d8138440d237cf6338a3da78e3ec4b0621 Mon Sep 17 00:00:00 2001 From: henoheno Date: Sun, 4 Nov 2007 00:17:52 +0900 Subject: [PATCH] BugTrack2/236: Care for readdir() returns FALSE --- lib/file.php | 44 +++++++++++++++++++++++--------------------- plugin/attach.inc.php | 5 ++--- plugin/dump.inc.php | 12 ++++++++---- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/lib/file.php b/lib/file.php index 400c204..979cb5c 100644 --- a/lib/file.php +++ b/lib/file.php @@ -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) { diff --git a/plugin/attach.inc.php b/plugin/attach.inc.php index 7fda592..bdbcb75 100644 --- a/plugin/attach.inc.php +++ b/plugin/attach.inc.php @@ -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]); diff --git a/plugin/dump.inc.php b/plugin/dump.inc.php index c8a54f7..763c144 100644 --- a/plugin/dump.inc.php +++ b/plugin/dump.inc.php @@ -1,5 +1,9 @@ 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); -- 2.11.0