OSDN Git Service

- fixed bug Ethna_Util#getRandom emits warning when "open_basedir" directive enabled.
authormumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Mon, 16 Jun 2008 19:30:31 +0000 (19:30 +0000)
committermumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Mon, 16 Jun 2008 19:30:31 +0000 (19:30 +0000)
CHANGES
class/Ethna_Util.php
test/Ethna_Util_Test.php

diff --git a/CHANGES b/CHANGES
index e58a4bc..5850aa8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -47,6 +47,8 @@
 -- selected="true" -> selected="selected"
 - アプリケーションIDの始めの文字に数値を許していたバグを修正
 -- クラス名のprefixになるため、数値を許すと自動生成物がコンパイルエラーを起こす
+- Ethna_Util#getRandom で open_basedir が有効な場合に、 /proc を開けず警告が出る点を回避(thanks. sotarok)
+-- http://d.hatena.ne.jp/sotarok/20070813/1187055110
 
 ** 2.3.5
 
index 115d692..5ed7acd 100644 (file)
@@ -569,9 +569,17 @@ class Ethna_Util
         $value = "";
         for ($i = 0; $i < 2; $i++) {
             // for Linux
-            if (file_exists('/proc/net/dev')) {
+            // open_basedir がオンで、かつ /proc が許可されているか?
+            // open_basedir が空なら許可されていると看做す
+            $devfile = '/proc/net/dev';
+            $open_basedir_conf = ini_get('open_basedir');
+            $devfile_enabled = (empty($open_basedir_conf) 
+                            || (preg_match('#:/proc#', $open_basedir_conf) > 0
+                            ||  preg_match('#^/proc#', $open_basedir_conf) > 0));
+
+            if ($devfile_enabled && file_exists($devfile)) {
                 $rx = $tx = 0;
-                $fp = fopen('/proc/net/dev', 'r');
+                $fp = fopen($devfile, 'r');
                 if ($fp != null) {
                     $header = true;
                     while (feof($fp) === false) {
index 18cdf7e..8c65055 100644 (file)
@@ -1,8 +1,10 @@
 <?php
+// vim: foldmethod=marker
 /**
  *  Ethna_Util_Test.php
  */
 
+error_reporting(E_ALL);
 /**
  *  Ethna_Utilクラスのテストケース(1)
  *
@@ -10,6 +12,7 @@
  */
 class Ethna_Util_Test extends Ethna_UnitTestBase
 {
+    // {{{  testIsRootDir
     function testIsRootDir()
     {
         $this->assertTrue(DIRECTORY_SEPARATOR);
@@ -28,8 +31,9 @@ class Ethna_Util_Test extends Ethna_UnitTestBase
             $this->assertFalse($util->isRootDir("/test.txt"));
         }
     }
+    // }}}
 
-
+    // {{{  testCheckMailAddress
     function testCheckMailAddress()
     {
         $fail_words = array(
@@ -51,7 +55,9 @@ class Ethna_Util_Test extends Ethna_UnitTestBase
         $result = $util->checkMailAddress('hoge@fuga.net');
         $this->assertTrue($result);
     }
+    // }}}
 
+    // {{{  testIsAbsolute
     function testIsAbsolute()
     {
         $absolute_paths = array(
@@ -73,6 +79,21 @@ class Ethna_Util_Test extends Ethna_UnitTestBase
         foreach ($invalid_params as $path) {
             $this->assertFalse(Ethna_Util::isAbsolute($path));
         }
-     }
+    }
+    // }}}
+
+    // {{{  testGetRandom
+    function testGetRandom()
+    {
+        //    いかなる状態であっても
+        //    値が得られなければならない
+        $r = Ethna_Util::getRandom();
+        $this->assertNotNULL($r);
+    }
+    // }}}
+
+
+
 }
+
 ?>