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.
This commit is contained in:
Tim Düsterhus 2023-01-07 14:03:13 +01:00 committed by GitHub
parent df96346f9c
commit 32f503e4e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

3
NEWS
View File

@ -30,6 +30,9 @@ PHP NEWS
- Posix:
. Fix memory leak in posix_ttyname() (girgias)
- Random:
. Fixed bug GH-10247 (Theoretical file descriptor leak for /dev/urandom). (timwolla)
- Standard:
. Fix GH-10187 (Segfault in stripslashes() with arm64). (nielsdos)

View File

@ -828,7 +828,7 @@ static PHP_GINIT_FUNCTION(random)
/* {{{ PHP_GSHUTDOWN_FUNCTION */
static PHP_GSHUTDOWN_FUNCTION(random)
{
if (random_globals->random_fd > 0) {
if (random_globals->random_fd >= 0) {
close(random_globals->random_fd);
random_globals->random_fd = -1;
}