Skip to content

Commit 32f503e

Browse files
authored
random: Fix check before closing random_fd (#10247)
If, for whatever reason, the random_fd has been assigned file descriptor `0` it previously failed to close during module shutdown, thus leaking the descriptor.
1 parent df96346 commit 32f503e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ PHP NEWS
3030
- Posix:
3131
. Fix memory leak in posix_ttyname() (girgias)
3232

33+
- Random:
34+
. Fixed bug GH-10247 (Theoretical file descriptor leak for /dev/urandom). (timwolla)
35+
3336
- Standard:
3437
. Fix GH-10187 (Segfault in stripslashes() with arm64). (nielsdos)
3538

ext/random/random.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ static PHP_GINIT_FUNCTION(random)
828828
/* {{{ PHP_GSHUTDOWN_FUNCTION */
829829
static PHP_GSHUTDOWN_FUNCTION(random)
830830
{
831-
if (random_globals->random_fd > 0) {
831+
if (random_globals->random_fd >= 0) {
832832
close(random_globals->random_fd);
833833
random_globals->random_fd = -1;
834834
}

0 commit comments

Comments
 (0)