ソースを参照

ZF-7603: better log facility validation

- Backported r22450 to trunk

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22451 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 15 年 前
コミット
f43d20f1fd
1 ファイル変更43 行追加2 行削除
  1. 43 2
      library/Zend/Log/Writer/Syslog.php

+ 43 - 2
library/Zend/Log/Writer/Syslog.php

@@ -75,11 +75,38 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract
 
     /**
      * Facility used by this syslog-writer instance
-     * @var string
+     * @var int
      */
     protected $_facility = LOG_USER;
 
     /**
+     * _validFacilities 
+     * 
+     * @var array
+     */
+    protected $_validFacilities = array(
+        LOG_AUTH,
+        LOG_AUTHPRIV,
+        LOG_CRON,
+        LOG_DAEMON,
+        LOG_KERN,
+        LOG_LOCAL0,
+        LOG_LOCAL1,
+        LOG_LOCAL2,
+        LOG_LOCAL3,
+        LOG_LOCAL4,
+        LOG_LOCAL5,
+        LOG_LOCAL6,
+        LOG_LOCAL7,
+        LOG_LPR,
+        LOG_MAIL,
+        LOG_NEWS,
+        LOG_SYSLOG,
+        LOG_USER,
+        LOG_UUCP,
+    );
+
+    /**
      * Class constructor
      *
      * @param  array $options Array of options; may include "application" and "facility" keys
@@ -125,14 +152,28 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract
     /**
      * Set syslog facility
      *
-     * @param  string $facility Syslog facility
+     * @param  int $facility Syslog facility
      * @return void
+     * @throws Zend_Log_Exception for invalid log facility
      */
     public function setFacility($facility)
     {
         if ($this->_facility === $facility) {
             return;
         }
+
+        if (!in_array($facility($this->_validFacilities))) {
+            require_once 'Zend/Log/Exception.php';
+            throw new Zend_Log_Exception('Invalid log facility provided; please see http://php.net/openlog for a list of valid facility values');
+        }
+
+        if (strstr(strtolower(PHP_OS), 'windows')
+            && ($facility !== LOG_USER)
+        ) {
+            require_once 'Zend/Log/Exception.php';
+            throw new Zend_Log_Exception('Only LOG_USER is a valid log facility on Windows');
+        }
+
         $this->_facility = $facility;
         $this->_initializeSyslog();
     }