Skip to content

Commit 269d160

Browse files
paragonie-scottkrakjoe
authored andcommitted
Fix bug #75409
1 parent 38be3c4 commit 269d160

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ PHP NEWS
1717
- Standard:
1818
. Fixed bug #75535 (Inappropriately parsing HTTP response leads to PHP
1919
segment fault). (Nikita)
20+
. Fixed bug #75409 (accept EFAULT in addition to ENOSYS as indicator
21+
that getrandom() is missing). (sarciszewski)
2022

2123
- Zip:
2224
. Fixed bug #75540 (Segfault with libzip 1.3.1). (Remi)

ext/standard/random.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,10 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, zend_bool should_throw)
122122
} else if (errno == EINTR || errno == EAGAIN) {
123123
/* Try again */
124124
continue;
125+
} else {
126+
/* If the syscall fails, fall back to reading from /dev/urandom */
127+
break;
125128
}
126-
/*
127-
If the syscall fails, we are doomed. The loop that calls
128-
php_random_bytes should be terminated by the exception instead
129-
of proceeding to demand more entropy.
130-
*/
131-
if (should_throw) {
132-
zend_throw_exception(zend_ce_exception, "Could not gather sufficient random data", errno);
133-
}
134-
return FAILURE;
135129
}
136130

137131
read_bytes += (size_t) n;

0 commit comments

Comments
 (0)