From 01817e99ab4da5938503eef952a2e933c4695eaf Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 7 Apr 2024 08:43:23 +0100 Subject: [PATCH] ext/pcntl pcntl_signal_get_handler update. The situation varies from platform to another, thus taking in account the complexity of it. Close GH-13902 --- NEWS | 2 ++ ext/pcntl/pcntl.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 465764628b0..3c994abb377 100644 --- a/NEWS +++ b/NEWS @@ -125,6 +125,8 @@ PHP NEWS - PCNTL: . Added pcntl_setns for Linux. (David Carlier) . Added pcntl_getaffinity/pcntl_setaffinity. (David Carlier) + . Updated pcntl_get_signal_handler signal id upper limit to be + more in line with platforms limits. (David Carlier) - PCRE: . Upgrade bundled pcre2lib to version 10.43. (nielsdos) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index fcd2315e8c2..891619afc60 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -692,8 +692,17 @@ PHP_FUNCTION(pcntl_signal_get_handler) Z_PARAM_LONG(signo) ZEND_PARSE_PARAMETERS_END(); - if (signo < 1 || signo > 32) { - zend_argument_value_error(1, "must be between 1 and 32"); + // note: max signal on mac is SIGUSR2 (31), no real time signals. + int sigmax = NSIG - 1; +#if defined(SIGRTMAX) + // oddily enough, NSIG on freebsd reports only 32 whereas SIGRTMIN starts at 65. + if (sigmax < SIGRTMAX) { + sigmax = SIGRTMAX; + } +#endif + + if (signo < 1 || signo > sigmax) { + zend_argument_value_error(1, "must be between 1 and %d", sigmax); RETURN_THROWS(); }