Skip to content

Commit 3e27401

Browse files
adsrkrakjoe
authored andcommitted
Fix segfault in pcntl_signal_handler (bug #73939)
1 parent 959c897 commit 3e27401

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

ext/pcntl/pcntl.c

+3-12
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,6 @@ PHP_RSHUTDOWN_FUNCTION(pcntl)
560560
while (PCNTL_G(head)) {
561561
sig = PCNTL_G(head);
562562
PCNTL_G(head) = sig->next;
563-
#ifdef HAVE_STRUCT_SIGINFO_T
564-
if (sig->siginfo) {
565-
zend_array_destroy(sig->siginfo);
566-
}
567-
#endif
568563
efree(sig);
569564
}
570565
while (PCNTL_G(spares)) {
@@ -1379,11 +1374,7 @@ static void pcntl_signal_handler(int signo)
13791374
psig->next = NULL;
13801375

13811376
#ifdef HAVE_STRUCT_SIGINFO_T
1382-
zval user_siginfo;
1383-
array_init(&user_siginfo);
1384-
pcntl_siginfo_to_zval(signo, siginfo, &user_siginfo);
1385-
psig->siginfo = zend_array_dup(Z_ARRVAL(user_siginfo));
1386-
zval_ptr_dtor(&user_siginfo);
1377+
psig->siginfo = *siginfo;
13871378
#endif
13881379

13891380
/* the head check is important, as the tick handler cannot atomically clear both
@@ -1428,14 +1419,14 @@ void pcntl_signal_dispatch()
14281419
PCNTL_G(head) = NULL; /* simple stores are atomic */
14291420

14301421
/* Allocate */
1431-
14321422
while (queue) {
14331423
if ((handle = zend_hash_index_find(&PCNTL_G(php_signal_table), queue->signo)) != NULL) {
14341424
if (Z_TYPE_P(handle) != IS_LONG) {
14351425
ZVAL_NULL(&retval);
14361426
ZVAL_LONG(&params[0], queue->signo);
14371427
#ifdef HAVE_STRUCT_SIGINFO_T
1438-
ZVAL_ARR(&params[1], queue->siginfo);
1428+
array_init(&params[1]);
1429+
pcntl_siginfo_to_zval(queue->signo, &queue->siginfo, &params[1]);
14391430
#else
14401431
ZVAL_NULL(&params[1]);
14411432
#endif

ext/pcntl/php_pcntl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct php_pcntl_pending_signal {
7777
struct php_pcntl_pending_signal *next;
7878
zend_long signo;
7979
#ifdef HAVE_STRUCT_SIGINFO_T
80-
zend_array *siginfo;
80+
siginfo_t siginfo;
8181
#endif
8282
};
8383

0 commit comments

Comments
 (0)