From cbb0efaeeb265ff8026dee1d049d57a8d2b5c133 Mon Sep 17 00:00:00 2001 From: SATO Kentaro Date: Wed, 18 Dec 2019 04:03:42 +0900 Subject: [PATCH] Fix #78402: pcntl_signal() misleading error message An error message can be misleading when a handler passed to pcntl_signal() is not callable. --- NEWS | 4 ++++ ext/pcntl/pcntl.c | 7 +++++-- ext/pcntl/tests/pcntl_signal.phpt | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 60e91f19df1..12f4edc672f 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,10 @@ PHP NEWS . Fixed bug #78923 (Artifacts when convoluting image with transparency). (wilson chen) +- Pcntl: + . Fixed bug #78402 (Converting null to string in error message is bad DX). + (SATŌ Kentarō) + - PDO_PgSQL: . Fixed bug #78983 (pdo_pgsql config.w32 cannot find libpq-fe.h). (SATŌ Kentarō) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index c6236f96636..11f6164eb8f 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -1005,6 +1005,7 @@ PHP_FUNCTION(pcntl_signal) zval *handle; zend_long signo; zend_bool restart_syscalls = 1; + char *error = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz|b", &signo, &handle, &restart_syscalls) == FAILURE) { return; @@ -1043,13 +1044,15 @@ PHP_FUNCTION(pcntl_signal) RETURN_TRUE; } - if (!zend_is_callable(handle, 0, NULL)) { + if (!zend_is_callable_ex(handle, NULL, 0, NULL, NULL, &error)) { zend_string *func_name = zend_get_callable_name(handle); PCNTL_G(last_error) = EINVAL; - php_error_docref(NULL, E_WARNING, "%s is not a callable function name error", ZSTR_VAL(func_name)); + php_error_docref(NULL, E_WARNING, "Specified handler \"%s\" is not callable (%s)", ZSTR_VAL(func_name), error); zend_string_release_ex(func_name, 0); + efree(error); RETURN_FALSE; } + ZEND_ASSERT(!error); /* Add the function name to our signal table */ handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle); diff --git a/ext/pcntl/tests/pcntl_signal.phpt b/ext/pcntl/tests/pcntl_signal.phpt index a6441935c11..953ff54eefd 100644 --- a/ext/pcntl/tests/pcntl_signal.phpt +++ b/ext/pcntl/tests/pcntl_signal.phpt @@ -42,6 +42,6 @@ bool(false) Warning: pcntl_signal(): Invalid signal %s bool(false) -Warning: pcntl_signal(): not callable is not a callable function name error in %s +Warning: pcntl_signal(): Specified handler "not callable" is not callable (%s) in %s bool(false) ok