Skip to content

Commit cbb0efa

Browse files
ranvisnikic
authored andcommitted
Fix #78402: pcntl_signal() misleading error message
An error message can be misleading when a handler passed to pcntl_signal() is not callable.
1 parent eb84693 commit cbb0efa

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ PHP NEWS
1313
. Fixed bug #78923 (Artifacts when convoluting image with transparency).
1414
(wilson chen)
1515

16+
- Pcntl:
17+
. Fixed bug #78402 (Converting null to string in error message is bad DX).
18+
(SATŌ Kentarō)
19+
1620
- PDO_PgSQL:
1721
. Fixed bug #78983 (pdo_pgsql config.w32 cannot find libpq-fe.h). (SATŌ
1822
Kentarō)

ext/pcntl/pcntl.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ PHP_FUNCTION(pcntl_signal)
10051005
zval *handle;
10061006
zend_long signo;
10071007
zend_bool restart_syscalls = 1;
1008+
char *error = NULL;
10081009

10091010
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz|b", &signo, &handle, &restart_syscalls) == FAILURE) {
10101011
return;
@@ -1043,13 +1044,15 @@ PHP_FUNCTION(pcntl_signal)
10431044
RETURN_TRUE;
10441045
}
10451046

1046-
if (!zend_is_callable(handle, 0, NULL)) {
1047+
if (!zend_is_callable_ex(handle, NULL, 0, NULL, NULL, &error)) {
10471048
zend_string *func_name = zend_get_callable_name(handle);
10481049
PCNTL_G(last_error) = EINVAL;
1049-
php_error_docref(NULL, E_WARNING, "%s is not a callable function name error", ZSTR_VAL(func_name));
1050+
php_error_docref(NULL, E_WARNING, "Specified handler \"%s\" is not callable (%s)", ZSTR_VAL(func_name), error);
10501051
zend_string_release_ex(func_name, 0);
1052+
efree(error);
10511053
RETURN_FALSE;
10521054
}
1055+
ZEND_ASSERT(!error);
10531056

10541057
/* Add the function name to our signal table */
10551058
handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle);

ext/pcntl/tests/pcntl_signal.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ bool(false)
4242
Warning: pcntl_signal(): Invalid signal %s
4343
bool(false)
4444

45-
Warning: pcntl_signal(): not callable is not a callable function name error in %s
45+
Warning: pcntl_signal(): Specified handler "not callable" is not callable (%s) in %s
4646
bool(false)
4747
ok

0 commit comments

Comments
 (0)