iliaa Tue, 23 Nov 2010 13:09:15 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=305692
Log: Fixed bug #46587 (mt_rand() does not check that max is greater than min). Bug: http://bugs.php.net/46587 (Assigned) mt_/rand produce out of range numbers when min = 0 and max > get_randmax Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/standard/rand.c U php/php-src/trunk/ext/standard/rand.c Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2010-11-23 12:41:38 UTC (rev 305691) +++ php/php-src/branches/PHP_5_3/NEWS 2010-11-23 13:09:15 UTC (rev 305692) @@ -9,6 +9,8 @@ EXTR_OVERWRITE. (jorto at redhat dot com) . Fixed bug #47168 (printf of floating point variable prints maximum of 40 decimal places). (Ilia) + . Fixed bug #46587 (mt_rand() does not check that max is greater than min). + (Ilia) - Intl extension: . Fixed crashes on invalid parameters in intl extension (Stas, Maksymilian Modified: php/php-src/branches/PHP_5_3/ext/standard/rand.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/standard/rand.c 2010-11-23 12:41:38 UTC (rev 305691) +++ php/php-src/branches/PHP_5_3/ext/standard/rand.c 2010-11-23 13:09:15 UTC (rev 305692) @@ -322,6 +322,11 @@ php_mt_srand(GENERATE_SEED() TSRMLS_CC); } + if (max < min) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "max(%d) is smaller than min(%d)", max, min); + RETURN_FALSE; + } + /* * Melo: hmms.. randomMT() returns 32 random bits... * Yet, the previous php_rand only returns 31 at most. Modified: php/php-src/trunk/ext/standard/rand.c =================================================================== --- php/php-src/trunk/ext/standard/rand.c 2010-11-23 12:41:38 UTC (rev 305691) +++ php/php-src/trunk/ext/standard/rand.c 2010-11-23 13:09:15 UTC (rev 305692) @@ -322,6 +322,11 @@ php_mt_srand(GENERATE_SEED() TSRMLS_CC); } + if (max < min) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "max(%d) is smaller than min(%d)", max, min); + RETURN_FALSE; + } + /* * Melo: hmms.. randomMT() returns 32 random bits... * Yet, the previous php_rand only returns 31 at most.
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php