From a7ebccad34a338eaab6dc13f293ab8d2ecda5fff Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 28 Jan 2026 18:42:16 +0000 Subject: [PATCH] Fix GH-21058: error_log() crash on null destination argument. we preserve the lower branches behavior by letting php_stream_open_wrapper_ex handling the null path and propagating the exception. close GH-21064 --- NEWS | 2 ++ ext/standard/basic_functions.c | 2 +- ext/standard/tests/general_functions/gh21058.phpt | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/general_functions/gh21058.phpt diff --git a/NEWS b/NEWS index bf00d8f663b90..be349610ff86f 100644 --- a/NEWS +++ b/NEWS @@ -101,6 +101,8 @@ PHP NEWS while COW violation flag is still set). (alexandre-daubois) . Invalid mode values now throw in array_filter() instead of being silently defaulted to 0. (Jorg Sowa) + . Fixed bug GH-21058 (error_log() crashes with message_type 3 and + null destination). (David Carlier) - Streams: . Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index dc6146aec9d9c..1d7f2c1a9b59d 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1369,7 +1369,7 @@ PHPAPI zend_result _php_error_log(int opt_err, const zend_string *message, const return FAILURE; case 3: /*save to a file */ - stream = php_stream_open_wrapper(ZSTR_VAL(opt), "a", REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(opt ? ZSTR_VAL(opt) : NULL, "a", REPORT_ERRORS, NULL); if (!stream) { return FAILURE; } diff --git a/ext/standard/tests/general_functions/gh21058.phpt b/ext/standard/tests/general_functions/gh21058.phpt new file mode 100644 index 0000000000000..598625a2017eb --- /dev/null +++ b/ext/standard/tests/general_functions/gh21058.phpt @@ -0,0 +1,13 @@ +--TEST-- +GH-21058 (error_log() crash with null destination and message type 3) +--FILE-- +getMessage(), PHP_EOL; +} +?> +--EXPECT-- +Path must not be empty