From 64f2f3f0827f7af901f8e6293b4fce072eb9b4e1 Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 9 Jan 2024 17:07:34 +0100 Subject: [PATCH] security/acme-client: fix shell processes getting stuck, refs #3745 This deals with the following issues that occured while performing extensive testing: - acme.sh processes got stuck forever - PHP memory exhaustion - PHP processes with high CPU usage --- .../mvc/app/library/OPNsense/AcmeClient/LeUtils.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/security/acme-client/src/opnsense/mvc/app/library/OPNsense/AcmeClient/LeUtils.php b/security/acme-client/src/opnsense/mvc/app/library/OPNsense/AcmeClient/LeUtils.php index cca7ce55e..abc57c4e5 100644 --- a/security/acme-client/src/opnsense/mvc/app/library/OPNsense/AcmeClient/LeUtils.php +++ b/security/acme-client/src/opnsense/mvc/app/library/OPNsense/AcmeClient/LeUtils.php @@ -197,14 +197,14 @@ class LeUtils // This workaround ensures that the accurate return code // is reliably returned. fclose($proc_pipes[0]); - $output = array(); - while (!feof($proc_pipes[1])) { - $output[] = rtrim(fgets($proc_pipes[1], 1024), "\n"); + stream_set_blocking($proc_pipes[1], false); + stream_set_blocking($proc_pipes[2], false); + while (!feof($proc_pipes[1]) || !feof($proc_pipes[2])) { + $stdout = fread($proc_pipes[1], 1024); + $stderr = fread($proc_pipes[2], 1024); + usleep(50000); } fclose($proc_pipes[1]); - while (!feof($proc_pipes[2])) { - $output[] = rtrim(fgets($proc_pipes[2], 1024), "\n"); - } fclose($proc_pipes[2]); // Get exit code