]> granicus.if.org Git - php/commitdiff
Fix use of uninitialised value in uniqid() where more_entropy=0
authorJulien Pauli <jpauli@php.net>
Tue, 1 Aug 2017 12:42:15 +0000 (14:42 +0200)
committerJulien Pauli <jpauli@php.net>
Tue, 1 Aug 2017 12:58:00 +0000 (14:58 +0200)
ext/standard/uniqid.c

index e8f2f19520ef2fd3a2de6a24c56f9e2c26532aab..8a6091a2af73ea6086391c5de49253881d3f32c5 100644 (file)
@@ -58,19 +58,17 @@ PHP_FUNCTION(uniqid)
                Z_PARAM_BOOL(more_entropy)
        ZEND_PARSE_PARAMETERS_END();
 
-       if (!more_entropy) {
-               /* This implementation needs current microsecond to change,
-                * hence we poll time until it does. This is much faster than
-                * calling usleep(1) which may cause the kernel to schedule
-                * another process, causing a pause of around 10ms.
-                */
-               do {
-                       (void)gettimeofday((struct timeval *) &tv, (struct timezone *) NULL);
-               } while (tv.tv_sec == prev_tv.tv_sec && tv.tv_usec == prev_tv.tv_usec);
+       /* This implementation needs current microsecond to change,
+        * hence we poll time until it does. This is much faster than
+        * calling usleep(1) which may cause the kernel to schedule
+        * another process, causing a pause of around 10ms.
+        */
+       do {
+               (void)gettimeofday((struct timeval *) &tv, (struct timezone *) NULL);
+       } while (tv.tv_sec == prev_tv.tv_sec && tv.tv_usec == prev_tv.tv_usec);
 
-               prev_tv.tv_sec = tv.tv_sec;
-               prev_tv.tv_usec = tv.tv_usec;
-       }
+       prev_tv.tv_sec = tv.tv_sec;
+       prev_tv.tv_usec = tv.tv_usec;
 
        sec = (int) tv.tv_sec;
        usec = (int) (tv.tv_usec % 0x100000);