Skip to content

Commit ad5222c

Browse files
author
Julien Pauli
committed
Fix use of uninitialised value in uniqid() where more_entropy=0
1 parent b8da481 commit ad5222c

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

ext/standard/uniqid.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,17 @@ PHP_FUNCTION(uniqid)
5858
Z_PARAM_BOOL(more_entropy)
5959
ZEND_PARSE_PARAMETERS_END();
6060

61-
if (!more_entropy) {
62-
/* This implementation needs current microsecond to change,
63-
* hence we poll time until it does. This is much faster than
64-
* calling usleep(1) which may cause the kernel to schedule
65-
* another process, causing a pause of around 10ms.
66-
*/
67-
do {
68-
(void)gettimeofday((struct timeval *) &tv, (struct timezone *) NULL);
69-
} while (tv.tv_sec == prev_tv.tv_sec && tv.tv_usec == prev_tv.tv_usec);
61+
/* This implementation needs current microsecond to change,
62+
* hence we poll time until it does. This is much faster than
63+
* calling usleep(1) which may cause the kernel to schedule
64+
* another process, causing a pause of around 10ms.
65+
*/
66+
do {
67+
(void)gettimeofday((struct timeval *) &tv, (struct timezone *) NULL);
68+
} while (tv.tv_sec == prev_tv.tv_sec && tv.tv_usec == prev_tv.tv_usec);
7069

71-
prev_tv.tv_sec = tv.tv_sec;
72-
prev_tv.tv_usec = tv.tv_usec;
73-
}
70+
prev_tv.tv_sec = tv.tv_sec;
71+
prev_tv.tv_usec = tv.tv_usec;
7472

7573
sec = (int) tv.tv_sec;
7674
usec = (int) (tv.tv_usec % 0x100000);

0 commit comments

Comments
 (0)