From 4d4994f974a3218f1f13256799e5cb16a665cb82 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 21 Feb 2026 03:52:49 +0000 Subject: [PATCH] ext/pcntl: Fix signal table updated before php_signal4 succeeds in pcntl_signal Move the signal table update after the php_signal4 call, mirroring what is already done in the SIG_DFL/SIG_IGN (integer) code path. This prevents a stale entry in the table if sigaction fails. --- ext/pcntl/pcntl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 2034ca80b05b8..44514ff515b5b 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -798,15 +798,16 @@ PHP_FUNCTION(pcntl_signal) RETURN_THROWS(); } - /* Add the function name to our signal table */ - handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle); - Z_TRY_ADDREF_P(handle); - + /* we need to register in the OS side first before we update the internal list */ if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == (void *)SIG_ERR) { PCNTL_G(last_error) = errno; php_error_docref(NULL, E_WARNING, "Error assigning signal"); RETURN_FALSE; } + + /* Add the function name to our signal table */ + handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle); + Z_TRY_ADDREF_P(handle); RETURN_TRUE; } /* }}} */