Browse Source

Merge pull request #2 from zendframework/master

Update to 1.17
Komarov Alexey 10 years ago
parent
commit
65251e999d

+ 2 - 2
README.md

@@ -7,10 +7,10 @@ Master: [![Build Status](https://api.travis-ci.org/zendframework/zf1.png?branch=
 RELEASE INFORMATION
 ===================
 
-Zend Framework 1.12.17dev Release.
+Zend Framework 1.12.18dev Release.
 Released on MMM DD, YYYY.
 
-IMPORTANT FIXES FOR 1.12.17
+IMPORTANT FIXES FOR 1.12.18
 ---------------------------
 
 See http://framework.zend.com/changelog for full details.

+ 17 - 12
library/Zend/Captcha/Word.php

@@ -22,6 +22,9 @@
 /** @see Zend_Captcha_Base */
 require_once 'Zend/Captcha/Base.php';
 
+/** @see Zend_Crypt_Math */
+require_once 'Zend/Crypt/Math.php';
+
 /**
  * Word-based captcha adapter
  *
@@ -39,10 +42,10 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
     /**#@+
      * @var array Character sets
      */
-    static $V  = array("a", "e", "i", "o", "u", "y");
-    static $VN = array("a", "e", "i", "o", "u", "y","2","3","4","5","6","7","8","9");
-    static $C  = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z");
-    static $CN = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z","2","3","4","5","6","7","8","9");
+    static public $V  = array("a", "e", "i", "o", "u", "y");
+    static public $VN = array("a", "e", "i", "o", "u", "y","2","3","4","5","6","7","8","9");
+    static public $C  = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z");
+    static public $CN = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z","2","3","4","5","6","7","8","9");
     /**#@-*/
 
     /**
@@ -175,7 +178,7 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
      *
      * @return string
      */
-    public function getId ()
+    public function getId()
     {
         if (null === $this->_id) {
             $this->_setId($this->_generateRandomId());
@@ -189,7 +192,7 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
      * @param string $id
      * @return Zend_Captcha_Word
      */
-    protected function _setId ($id)
+    protected function _setId($id)
     {
         $this->_id = $id;
         return $this;
@@ -250,7 +253,7 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
         $this->_useNumbers = $_useNumbers;
         return $this;
     }
-    
+
     /**
      * Get session object
      *
@@ -280,7 +283,7 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
     public function setSession(Zend_Session_Namespace $session)
     {
         $this->_session = $session;
-        if($session) {
+        if ($session) {
             $this->_keepSession = true;
         }
         return $this;
@@ -326,10 +329,12 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
         $vowels     = $this->_useNumbers ? self::$VN : self::$V;
         $consonants = $this->_useNumbers ? self::$CN : self::$C;
 
+        $totIndexCon = count($consonants) - 1;
+        $totIndexVow = count($vowels) - 1;
         for ($i=0; $i < $wordLen; $i = $i + 2) {
             // generate word with mix of vowels and consonants
-            $consonant = $consonants[array_rand($consonants)];
-            $vowel     = $vowels[array_rand($vowels)];
+            $consonant = $consonants[Zend_Crypt_Math::randInteger(0, $totIndexCon, true)];
+            $vowel     = $vowels[Zend_Crypt_Math::randInteger(0, $totIndexVow, true)];
             $word     .= $consonant . $vowel;
         }
 
@@ -347,7 +352,7 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
      */
     public function generate()
     {
-        if(!$this->_keepSession) {
+        if (!$this->_keepSession) {
             $this->_session = null;
         }
         $id = $this->_generateRandomId();
@@ -359,7 +364,7 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
 
     protected function _generateRandomId()
     {
-        return md5(mt_rand(0, 1000) . microtime(true));
+        return md5(Zend_Crypt_Math::randBytes(32));
     }
 
     /**

+ 0 - 2
library/Zend/Cloud/AbstractFactory.php

@@ -30,8 +30,6 @@ class Zend_Cloud_AbstractFactory
 {
     /**
      * Constructor
-     *
-     * @return void
      */
     private function __construct()
     {

+ 2 - 3
library/Zend/Cloud/QueueService/Factory.php

@@ -39,8 +39,6 @@ class Zend_Cloud_QueueService_Factory extends Zend_Cloud_AbstractFactory
 
     /**
      * Constructor
-     *
-     * @return void
      */
     private function __construct()
     {
@@ -51,7 +49,8 @@ class Zend_Cloud_QueueService_Factory extends Zend_Cloud_AbstractFactory
      * Retrieve QueueService adapter
      *
      * @param  array $options
-     * @return void
+     * @return null|Zend_Cloud_DocumentService_Adapter|Zend_Cloud_QueueService_Adapter|Zend_Cloud_StorageService_Adapter
+     * @throws Zend_Cloud_QueueService_Exception
      */
     public static function getAdapter($options = array())
     {

+ 94 - 6
library/Zend/Crypt/Math.php

@@ -57,21 +57,109 @@ class Zend_Crypt_Math extends Zend_Crypt_Math_BigInteger
         }
         $rand = '';
         $i2 = strlen($maximum) - 1;
-        for ($i = 1;$i < $i2;$i++) {
-            $rand .= mt_rand(0,9);
+        for ($i = 1; $i < $i2; $i++) {
+            $rand .= mt_rand(0, 9);
         }
-        $rand .= mt_rand(0,9);
+        $rand .= mt_rand(0, 9);
         return $rand;
     }
 
     /**
+     * Return a random strings of $length bytes
+     *
+     * @param  integer $length
+     * @param  boolean $strong
+     * @return string
+     */
+    public static function randBytes($length, $strong = false)
+    {
+        $length = (int) $length;
+        if ($length <= 0) {
+            return false;
+        }
+        if (function_exists('openssl_random_pseudo_bytes')) {
+            $bytes = openssl_random_pseudo_bytes($length, $usable);
+            if ($strong === $usable) {
+                return $bytes;
+            }
+        }
+        if (function_exists('mcrypt_create_iv')) {
+            $bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
+            if ($bytes !== false && strlen($bytes) === $length) {
+                return $bytes;
+            }
+        }
+        if (file_exists('/dev/urandom') && is_readable('/dev/urandom')) {
+            $frandom = fopen('/dev/urandom', 'r');
+            if ($frandom !== false) {
+                return fread($frandom, $length);
+            }
+        }
+        if (true === $strong) {
+            require_once 'Zend/Crypt/Exception.php';
+            throw new Zend_Crypt_Exception(
+                'This PHP environment doesn\'t support secure random number generation. ' .
+                'Please consider installing the OpenSSL and/or Mcrypt extensions'
+            );
+        }
+        $rand = '';
+        for ($i = 0; $i < $length; $i++) {
+            $rand .= chr(mt_rand(0, 255));
+        }
+        return $rand;
+    }
+
+    /**
+     * Return a random integer between $min and $max
+     *
+     * @param  integer $min
+     * @param  integer $max
+     * @param  boolean $strong
+     * @return integer
+     */
+    public static function randInteger($min, $max, $strong = false)
+    {
+        if ($min > $max) {
+            require_once 'Zend/Crypt/Exception.php';
+            throw new Zend_Crypt_Exception(
+                'The min parameter must be lower than max parameter'
+            );
+        }
+        $range = $max - $min;
+        if ($range == 0) {
+            return $max;
+        } elseif ($range > PHP_INT_MAX || is_float($range)) {
+            require_once 'Zend/Crypt/Exception.php';
+            throw new Zend_Crypt_Exception(
+                'The supplied range is too great to generate'
+            );
+        }
+        // calculate number of bits required to store range on this machine
+        $r = $range;
+        $bits = 0;
+        while ($r) {
+            $bits++;
+            $r >>= 1;
+        }
+        $bits   = (int) max($bits, 1);
+        $bytes  = (int) max(ceil($bits / 8), 1);
+        $filter = (int) ((1 << $bits) - 1);
+        do {
+            $rnd  = hexdec(bin2hex(self::randBytes($bytes, $strong)));
+            $rnd &= $filter;
+        } while ($rnd > $range);
+        return ($min + $rnd);
+    }
+
+    /**
      * Get the big endian two's complement of a given big integer in
      * binary notation
      *
      * @param string $long
      * @return string
      */
-    public function btwoc($long) {
+    public function btwoc($long)
+    {
         if (ord($long[0]) > 127) {
             return "\x00" . $long;
         }
@@ -84,7 +172,8 @@ class Zend_Crypt_Math extends Zend_Crypt_Math_BigInteger
      * @param string $binary
      * @return string
      */
-    public function fromBinary($binary) {
+    public function fromBinary($binary)
+    {
         return $this->_math->binaryToInteger($binary);
     }
 
@@ -98,5 +187,4 @@ class Zend_Crypt_Math extends Zend_Crypt_Math_BigInteger
     {
         return $this->_math->integerToBinary($integer);
     }
-
 }

+ 26 - 0
library/Zend/Validate/Hostname.php

@@ -156,9 +156,11 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'aq',
         'aquarelle',
         'ar',
+        'aramco',
         'archi',
         'army',
         'arpa',
+        'arte',
         'as',
         'asia',
         'associates',
@@ -213,12 +215,14 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'bloomberg',
         'blue',
         'bm',
+        'bms',
         'bmw',
         'bn',
         'bnl',
         'bnpparibas',
         'bo',
         'boats',
+        'bom',
         'bond',
         'boo',
         'boots',
@@ -286,6 +290,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'chrome',
         'church',
         'ci',
+        'cipriani',
         'cisco',
         'citic',
         'city',
@@ -298,6 +303,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'clothing',
         'cloud',
         'club',
+        'clubmed',
         'cm',
         'cn',
         'co',
@@ -351,6 +357,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'deals',
         'degree',
         'delivery',
+        'dell',
         'delta',
         'democrat',
         'dental',
@@ -420,6 +427,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'feedback',
         'fi',
         'film',
+        'final',
         'finance',
         'financial',
         'firmdale',
@@ -500,6 +508,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'gs',
         'gt',
         'gu',
+        'gucci',
         'guge',
         'guide',
         'guitars',
@@ -536,6 +545,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'hsbc',
         'ht',
         'hu',
+        'hyundai',
         'ibm',
         'icbc',
         'ice',
@@ -570,6 +580,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'it',
         'itau',
         'iwc',
+        'jaguar',
         'java',
         'jcb',
         'je',
@@ -590,7 +601,9 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'kg',
         'kh',
         'ki',
+        'kia',
         'kim',
+        'kinder',
         'kitchen',
         'kiwi',
         'km',
@@ -609,6 +622,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'lacaixa',
         'lancaster',
         'land',
+        'landrover',
         'lasalle',
         'lat',
         'latrobe',
@@ -644,6 +658,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'lr',
         'ls',
         'lt',
+        'ltd',
         'ltda',
         'lu',
         'lupin',
@@ -688,6 +703,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'mobi',
         'moda',
         'moe',
+        'moi',
         'mom',
         'monash',
         'money',
@@ -706,8 +722,10 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'mt',
         'mtn',
         'mtpc',
+        'mtr',
         'mu',
         'museum',
+        'mutuelle',
         'mv',
         'mw',
         'mx',
@@ -747,6 +765,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'nu',
         'nyc',
         'nz',
+        'obi',
         'office',
         'okinawa',
         'om',
@@ -851,6 +870,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'ruhr',
         'run',
         'rw',
+        'rwe',
         'ryukyu',
         'sa',
         'saarland',
@@ -882,6 +902,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'seek',
         'sener',
         'services',
+        'seven',
         'sew',
         'sex',
         'sexy',
@@ -923,6 +944,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'statoil',
         'stc',
         'stcgroup',
+        'stockholm',
         'studio',
         'study',
         'style',
@@ -1019,6 +1041,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'video',
         'villas',
         'vin',
+        'virgin',
         'vision',
         'vista',
         'vistaprint',
@@ -1118,6 +1141,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'xn--l1acc',
         'xn--lgbbat1ad8j',
         'xn--mgb9awbf',
+        'xn--mgba3a3ejt',
         'xn--mgba3a4f16a',
         'xn--mgbaam7a8h',
         'xn--mgbab2bd',
@@ -1165,6 +1189,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'xxx',
         'xyz',
         'yachts',
+        'yamaxun',
         'yandex',
         'ye',
         'yodobashi',
@@ -1173,6 +1198,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
         'youtube',
         'yt',
         'za',
+        'zara',
         'zip',
         'zm',
         'zone',

+ 1 - 1
library/Zend/Version.php

@@ -32,7 +32,7 @@ final class Zend_Version
     /**
      * Zend Framework version identification - see compareVersion()
      */
-    const VERSION = '1.12.17dev';
+    const VERSION = '1.12.18dev';
 
     /**
      * The latest stable version Zend Framework available

+ 6 - 1
library/Zend/Wildfire/Plugin/FirePhp.php

@@ -532,7 +532,12 @@ class Zend_Wildfire_Plugin_FirePhp implements Zend_Wildfire_Plugin_Interface
                 isset($trace[0]['file']) && substr($trace[0]['file'], -7, 7)=='Log.php' &&
                 isset($trace[1]['function']) && $trace[1]['function']=='__call') {
 
-                $trace = array_splice($trace, 2);
+                $spliceOffset = 2;
+                //Debug backtrace changed in PHP 7.0.0
+                if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
+                    $spliceOffset = 1;
+                }
+                $trace = array_splice($trace, $spliceOffset);
             }
         }
 

+ 72 - 3
tests/Zend/Crypt/MathTest.php

@@ -21,7 +21,7 @@
  */
 
 require_once 'Zend/Crypt/Math.php';
-
+require_once 'Zend/Crypt/Exception.php';
 
 /**
  * @category   Zend
@@ -36,8 +36,7 @@ class Zend_Crypt_MathTest extends PHPUnit_Framework_TestCase
 
     public function testRand()
     {
-        if (!extension_loaded('bcmath'))
-        {
+        if (!extension_loaded('bcmath')) {
             $this->markTestSkipped('Extension bcmath not loaded');
         }
 
@@ -59,4 +58,74 @@ class Zend_Crypt_MathTest extends PHPUnit_Framework_TestCase
         $this->assertTrue(bccomp($result, $lower) !== '-1');
     }
 
+    public function testRandBytes()
+    {
+        for ($length = 1; $length < 4096; $length++) {
+            $rand = Zend_Crypt_Math::randBytes($length);
+            $this->assertTrue(false !== $rand);
+            $this->assertEquals($length, strlen($rand));
+        }
+    }
+
+    public function testRandInteger()
+    {
+        for ($i = 0; $i < 1024; $i++) {
+            $min = rand(1, PHP_INT_MAX/2);
+            $max = $min + rand(1, PHP_INT_MAX/2 - 1);
+            $rand = Zend_Crypt_Math::randInteger($min, $max);
+            $this->assertGreaterThanOrEqual($min, $rand);
+            $this->assertLessThanOrEqual($max, $rand);
+        }
+    }
+
+    public static function provideRandInt()
+    {
+        return array(
+            array(2, 1, 10000, 100, 0.9, 1.1, false),
+            array(2, 1, 10000, 100, 0.8, 1.2, true)
+        );
+    }
+
+    /**
+     * A Monte Carlo test that generates $cycles numbers from 0 to $tot
+     * and test if the numbers are above or below the line y=x with a
+     * frequency range of [$min, $max]
+     *
+     * @dataProvider provideRandInt
+     */
+    public function testMontecarloRandInteger($num, $valid, $cycles, $tot, $min, $max, $strong)
+    {
+        try {
+            $test = Zend_Crypt_Math::randBytes(1, $strong);
+        } catch (Zend_Crypt_Exception $e) {
+            $this->markTestSkipped($e->getMessage());
+        }
+
+        $i     = 0;
+        $count = 0;
+        do {
+            $up   = 0;
+            $down = 0;
+            for ($i = 0; $i < $cycles; $i++) {
+                $x = Zend_Crypt_Math::randInteger(0, $tot, $strong);
+                $y = Zend_Crypt_Math::randInteger(0, $tot, $strong);
+                if ($x > $y) {
+                    $up++;
+                } elseif ($x < $y) {
+                    $down++;
+                }
+            }
+            $this->assertGreaterThan(0, $up);
+            $this->assertGreaterThan(0, $down);
+            $ratio = $up / $down;
+            if ($ratio > $min && $ratio < $max) {
+                $count++;
+            }
+            $i++;
+        } while ($i < $num && $count < $valid);
+
+        if ($count < $valid) {
+            $this->fail('The random number generator failed the Monte Carlo test');
+        }
+    }
 }

+ 1 - 1
tests/Zend/Db/Adapter/Pdo/TestCommon.php

@@ -98,6 +98,6 @@ abstract class Zend_Db_Adapter_Pdo_TestCommon extends Zend_Db_Adapter_TestCommon
     {
         $string = "1\0";
         $value  = $this->_db->quote($string);
-        $this->assertEquals("'1\\000'", $value);
+        $this->assertNotContains("\0", $value);
     }
 }

+ 6 - 0
tests/Zend/Soap/AllTests.php

@@ -51,6 +51,12 @@ class Zend_Soap_AllTests
     {
         $suite = new PHPUnit_Framework_TestSuite('Zend Framework - Zend_Soap');
 
+        //early exit because of segfault in this specific version
+        //https://github.com/zendframework/zf1/issues/650
+        if (getenv('TRAVIS') && version_compare(PHP_VERSION, '5.4.37', '=')) {
+            return $suite;
+        }
+
         $suite->addTestSuite('Zend_Soap_ClientTest');
         $suite->addTestSuite('Zend_Soap_ServerTest');
         $suite->addTestSuite('Zend_Soap_WsdlTest');