From 889ab0aa60b65f3e73e96baa141d7444905ea64c Mon Sep 17 00:00:00 2001 From: mumumu-org Date: Mon, 16 Jun 2008 19:30:31 +0000 Subject: [PATCH] - fixed bug Ethna_Util#getRandom emits warning when "open_basedir" directive enabled. --- CHANGES | 2 ++ class/Ethna_Util.php | 12 ++++++++++-- test/Ethna_Util_Test.php | 25 +++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index e58a4bc..5850aa8 100644 --- 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 diff --git a/class/Ethna_Util.php b/class/Ethna_Util.php index 115d692..5ed7acd 100644 --- a/class/Ethna_Util.php +++ b/class/Ethna_Util.php @@ -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) { diff --git a/test/Ethna_Util_Test.php b/test/Ethna_Util_Test.php index 18cdf7e..8c65055 100644 --- a/test/Ethna_Util_Test.php +++ b/test/Ethna_Util_Test.php @@ -1,8 +1,10 @@ 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); + } + // }}} + + + } + ?> -- 2.11.0