Skip to content

Commit 6a1bde5

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. close GH-21270
1 parent 37ce67f commit 6a1bde5

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ PHP NEWS
4343

4444
- PCNTL:
4545
. Fixed pcntl_setns() internal errors handling regarding errnos.
46-
(David Carlier)
46+
(David Carlier/ndossche)
4747
. Fixed cpuset leak in pcntl_setcpuaffinity on out-of-range CPU ID
4848
on NetBSD/Solaris platforms. (David Carlier)
49+
. Fixed pcntl_signal() signal table registering the callback first
50+
OS-wise before the internal list. (David Carlier)
4951

5052
- PDO_PGSQL:
5153
. Fixed bug GH-21055 (connection attribute status typo for GSS negotiation).

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+
/* Register with the OS first so that on failure we don't record a handler that was never installed */
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)