1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

ext/pcntl: fix pcntl_signal_dispatch() stale tail pointer and exception handling.

close GH-21259
This commit is contained in:
David Carlier
2026-02-19 20:07:44 +00:00
parent db6cca26dd
commit 296fad10fb
3 changed files with 48 additions and 0 deletions

2
NEWS
View File

@@ -50,6 +50,8 @@ PHP NEWS
on NetBSD/Solaris platforms. (David Carlier) on NetBSD/Solaris platforms. (David Carlier)
. Fixed pcntl_signal() signal table registering the callback first . Fixed pcntl_signal() signal table registering the callback first
OS-wise before the internal list. (David Carlier) OS-wise before the internal list. (David Carlier)
. Fixed pcntl_signal_dispatch() stale pointer and exception
handling. (David Carlier)
- PDO_PGSQL: - PDO_PGSQL:
. Fixed bug GH-21055 (connection attribute status typo for GSS negotiation). . Fixed bug GH-21055 (connection attribute status typo for GSS negotiation).

View File

@@ -1343,6 +1343,7 @@ void pcntl_signal_dispatch(void)
queue = PCNTL_G(head); queue = PCNTL_G(head);
PCNTL_G(head) = NULL; /* simple stores are atomic */ PCNTL_G(head) = NULL; /* simple stores are atomic */
PCNTL_G(tail) = NULL;
/* Allocate */ /* Allocate */
while (queue) { while (queue) {
@@ -1364,6 +1365,9 @@ void pcntl_signal_dispatch(void)
#ifdef HAVE_STRUCT_SIGINFO_T #ifdef HAVE_STRUCT_SIGINFO_T
zval_ptr_dtor(&params[1]); zval_ptr_dtor(&params[1]);
#endif #endif
if (EG(exception)) {
break;
}
} }
} }
@@ -1373,6 +1377,14 @@ void pcntl_signal_dispatch(void)
queue = next; queue = next;
} }
/* drain the remaining in case of exception thrown */
while (queue) {
next = queue->next;
queue->next = PCNTL_G(spares);
PCNTL_G(spares) = queue;
queue = next;
}
PCNTL_G(pending_signals) = 0; PCNTL_G(pending_signals) = 0;
/* Re-enable queue */ /* Re-enable queue */

View File

@@ -0,0 +1,34 @@
--TEST--
pcntl_signal_dispatch() stops dispatching after handler throws exception
--EXTENSIONS--
pcntl
posix
--FILE--
<?php
$called = [];
pcntl_signal(SIGUSR1, function ($signo) use (&$called) {
$called[] = 'SIGUSR1';
throw new \Exception('Exception in signal handler');
});
pcntl_signal(SIGUSR2, function ($signo) use (&$called) {
$called[] = 'SIGUSR2';
});
posix_kill(posix_getpid(), SIGUSR1);
posix_kill(posix_getpid(), SIGUSR2);
try {
pcntl_signal_dispatch();
} catch (\Exception $e) {
echo $e->getMessage() . "\n";
}
echo "Handlers called: " . implode(', ', $called) . "\n";
?>
--EXPECT--
Exception in signal handler
Handlers called: SIGUSR1