]> granicus.if.org Git - php/commitdiff
Fixed bug #46587 (mt_rand() does not check that max is greater than min).
authorIlia Alshanetsky <iliaa@php.net>
Tue, 23 Nov 2010 13:09:15 +0000 (13:09 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 23 Nov 2010 13:09:15 +0000 (13:09 +0000)
ext/standard/rand.c

index 4f1f18b2781b3f37525d00a22eb17d0b584faa83..eb26cc5c500c2a88fea7f4edc79f5cd9df7532de 100644 (file)
@@ -322,6 +322,11 @@ PHP_FUNCTION(mt_rand)
                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.