• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂769706fb8b5ffc1927c81705bfd333720527a805 (tree)
時間2014-11-30 12:56:52
作者henoheno <henoheno>
Commiterumorigu

Log Message

BugTrack2/236: Care for readdir() returns FALSE

Change Summary

差異

--- a/lib/file.php
+++ b/lib/file.php
@@ -510,21 +510,36 @@ function header_lastmod($page = NULL)
510510 }
511511 }
512512
513+// Get a list of encoded files (must specify a directory and a suffix)
514+function get_existfiles($dir = DATA_DIR, $ext = '.txt')
515+{
516+ $aryret = array();
517+ $pattern = '/^(?:[0-9A-F]{2})+' . preg_quote($ext, '/') . '$/';
518+
519+ $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.');
520+ while (($file = readdir($dp)) !== FALSE) {
521+ if (preg_match($pattern, $file)) {
522+ $aryret[] = $dir . $file;
523+ }
524+ }
525+ closedir($dp);
526+
527+ return $aryret;
528+}
529+
513530 // Get a page list of this wiki
514531 function get_existpages($dir = DATA_DIR, $ext = '.txt')
515532 {
516533 $aryret = array();
534+ $pattern = '/^((?:[0-9A-F]{2})+)' . preg_quote($ext, '/') . '$/';
517535
518- $pattern = '((?:[0-9A-F]{2})+)';
519- if ($ext != '') $ext = preg_quote($ext, '/');
520- $pattern = '/^' . $pattern . $ext . '$/';
521-
522- $dp = @opendir($dir) or
523- die_message($dir . ' is not found or not readable.');
536+ $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.');
524537 $matches = array();
525- while ($file = readdir($dp))
526- if (preg_match($pattern, $file, $matches))
538+ while (($file = readdir($dp)) !== FALSE) {
539+ if (preg_match($pattern, $file, $matches)) {
527540 $aryret[$file] = decode($matches[1]);
541+ }
542+ }
528543 closedir($dp);
529544
530545 return $aryret;
@@ -691,19 +706,6 @@ function get_readings()
691706 return $readings;
692707 }
693708
694-// Get a list of encoded files (must specify a directory and a suffix)
695-function get_existfiles($dir, $ext)
696-{
697- $pattern = '/^(?:[0-9A-F]{2})+' . preg_quote($ext, '/') . '$/';
698- $aryret = array();
699- $dp = @opendir($dir) or die_message($dir . ' is not found or not readable.');
700- while ($file = readdir($dp))
701- if (preg_match($pattern, $file))
702- $aryret[] = $dir . $file;
703- closedir($dp);
704- return $aryret;
705-}
706-
707709 // Get a list of related pages of the page
708710 function links_get_related($page)
709711 {
--- a/plugin/attach.inc.php
+++ b/plugin/attach.inc.php
@@ -818,9 +818,8 @@ class AttachPages
818818 $pattern = "/^({$page_pattern})_((?:[0-9A-F]{2})+){$age_pattern}$/";
819819
820820 $matches = array();
821- while ($file = readdir($dir)) {
822- if (! preg_match($pattern, $file, $matches))
823- continue;
821+ while (($file = readdir($dir)) !== FALSE) {
822+ if (! preg_match($pattern, $file, $matches)) continue;
824823
825824 $_page = decode($matches[1]);
826825 $_file = decode($matches[2]);
--- a/plugin/dump.inc.php
+++ b/plugin/dump.inc.php
@@ -1,5 +1,9 @@
11 <?php
2-// $Id: dump.inc.php,v 1.38 2007/05/12 09:17:14 henoheno Exp $
2+// $Id: dump.inc.php,v 1.41 2007/11/03 15:17:52 henoheno Exp $
3+// Copyright (C)
4+// 2004-2007 PukiWiki Developers Team
5+// 2004 teanan / Interfair Laboratory
6+// License: GPL v2 or (at your option) any later version
37 //
48 // Remote dump / restore plugin
59 // Originated as tarfile.inc.php by teanan / Interfair Laboratory 2004.
@@ -386,10 +390,10 @@ class tarlib
386390 @unlink($this->filename);
387391 die_message($dir . ' is not found or not readable.');
388392 }
389-
390- while ($filename = readdir($dp)) {
391- if (preg_match("/$mask/", $filename))
393+ while (($filename = readdir($dp)) !== FALSE) {
394+ if (preg_match('/' . $mask . '/', $filename)) {
392395 $files[] = $dir . $filename;
396+ }
393397 }
394398 closedir($dp);
395399