修訂 | 769706fb8b5ffc1927c81705bfd333720527a805 (tree) |
---|---|
時間 | 2014-11-30 12:56:52 |
作者 | henoheno <henoheno> |
Commiter | umorigu |
BugTrack2/236: Care for readdir() returns FALSE
@@ -510,21 +510,36 @@ function header_lastmod($page = NULL) | ||
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
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 | + | |
513 | 530 | // Get a page list of this wiki |
514 | 531 | function get_existpages($dir = DATA_DIR, $ext = '.txt') |
515 | 532 | { |
516 | 533 | $aryret = array(); |
534 | + $pattern = '/^((?:[0-9A-F]{2})+)' . preg_quote($ext, '/') . '$/'; | |
517 | 535 | |
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.'); | |
524 | 537 | $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)) { | |
527 | 540 | $aryret[$file] = decode($matches[1]); |
541 | + } | |
542 | + } | |
528 | 543 | closedir($dp); |
529 | 544 | |
530 | 545 | return $aryret; |
@@ -691,19 +706,6 @@ function get_readings() | ||
691 | 706 | return $readings; |
692 | 707 | } |
693 | 708 | |
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 | - | |
707 | 709 | // Get a list of related pages of the page |
708 | 710 | function links_get_related($page) |
709 | 711 | { |
@@ -818,9 +818,8 @@ class AttachPages | ||
818 | 818 | $pattern = "/^({$page_pattern})_((?:[0-9A-F]{2})+){$age_pattern}$/"; |
819 | 819 | |
820 | 820 | $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; | |
824 | 823 | |
825 | 824 | $_page = decode($matches[1]); |
826 | 825 | $_file = decode($matches[2]); |
@@ -1,5 +1,9 @@ | ||
1 | 1 | <?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 | |
3 | 7 | // |
4 | 8 | // Remote dump / restore plugin |
5 | 9 | // Originated as tarfile.inc.php by teanan / Interfair Laboratory 2004. |
@@ -386,10 +390,10 @@ class tarlib | ||
386 | 390 | @unlink($this->filename); |
387 | 391 | die_message($dir . ' is not found or not readable.'); |
388 | 392 | } |
389 | - | |
390 | - while ($filename = readdir($dp)) { | |
391 | - if (preg_match("/$mask/", $filename)) | |
393 | + while (($filename = readdir($dp)) !== FALSE) { | |
394 | + if (preg_match('/' . $mask . '/', $filename)) { | |
392 | 395 | $files[] = $dir . $filename; |
396 | + } | |
393 | 397 | } |
394 | 398 | closedir($dp); |
395 | 399 |