From f7c0185d5b5ed261a9290dd31ea8ee994e0b9e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 6 Jan 2023 20:29:44 +0100 Subject: [PATCH 1/2] random: Fix check before closing `random_fd` 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. --- ext/random/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/random/random.c b/ext/random/random.c index 161eb8e685203..64e30e5087186 100644 --- a/ext/random/random.c +++ b/ext/random/random.c @@ -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; } From e0a7ce476c4d65a873bbd4a4a103e76bd4b19f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 7 Jan 2023 14:02:12 +0100 Subject: [PATCH 2/2] [ci skip] NEWS --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index 22b1a57967447..57e947cf59fbd 100644 --- a/NEWS +++ b/NEWS @@ -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)