Skip to content

Commit 4d4994f

Browse files
committed
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.
1 parent 70b2761 commit 4d4994f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ext/pcntl/pcntl.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,15 +798,16 @@ PHP_FUNCTION(pcntl_signal)
798798
RETURN_THROWS();
799799
}
800800

801-
/* Add the function name to our signal table */
802-
handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle);
803-
Z_TRY_ADDREF_P(handle);
804-
801+
/* we need to register in the OS side first before we update the internal list */
805802
if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == (void *)SIG_ERR) {
806803
PCNTL_G(last_error) = errno;
807804
php_error_docref(NULL, E_WARNING, "Error assigning signal");
808805
RETURN_FALSE;
809806
}
807+
808+
/* Add the function name to our signal table */
809+
handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle);
810+
Z_TRY_ADDREF_P(handle);
810811
RETURN_TRUE;
811812
}
812813
/* }}} */

0 commit comments

Comments
 (0)