From e946b905b6df8aa86ec1463f9137387bf41c0e93 Mon Sep 17 00:00:00 2001 From: Robert Landers Date: Mon, 25 Dec 2023 11:03:00 +0100 Subject: [PATCH] Fix signal leak in max execution timers ts_resource() and php_request_startup() both eventually call zend_max_execution_timer_init(), which didn't have a guard to prevent recreating signal handlers, thus resulting in leaking signals. This adds a guard to prevent the leak. --- Zend/zend_max_execution_timer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Zend/zend_max_execution_timer.c b/Zend/zend_max_execution_timer.c index 480631dcb169a..48a4d1bd66415 100644 --- a/Zend/zend_max_execution_timer.c +++ b/Zend/zend_max_execution_timer.c @@ -35,6 +35,12 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ { + pid_t pid = getpid(); + + if (EG(pid) == pid) { + return; + } + struct sigevent sev; sev.sigev_notify = SIGEV_THREAD_ID; sev.sigev_value.sival_ptr = &EG(max_execution_timer_timer); @@ -48,9 +54,9 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */ EG(pid) = getpid(); -# ifdef MAX_EXECUTION_TIMERS_DEBUG +# ifdef MAX_EXECUTION_TIMERS_DEBUG fprintf(stderr, "Timer %#jx created on thread %d\n", (uintmax_t) EG(max_execution_timer_timer), sev.sigev_notify_thread_id); -# endif +# endif sigaction(sev.sigev_signo, NULL, &EG(oldact)); }