Skip to content

Commit a7ebcca

Browse files
committed
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
1 parent b16e534 commit a7ebcca

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ PHP NEWS
101101
while COW violation flag is still set). (alexandre-daubois)
102102
. Invalid mode values now throw in array_filter() instead of being silently
103103
defaulted to 0. (Jorg Sowa)
104+
. Fixed bug GH-21058 (error_log() crashes with message_type 3 and
105+
null destination). (David Carlier)
104106

105107
- Streams:
106108
. Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ PHPAPI zend_result _php_error_log(int opt_err, const zend_string *message, const
13691369
return FAILURE;
13701370

13711371
case 3: /*save to a file */
1372-
stream = php_stream_open_wrapper(ZSTR_VAL(opt), "a", REPORT_ERRORS, NULL);
1372+
stream = php_stream_open_wrapper(opt ? ZSTR_VAL(opt) : NULL, "a", REPORT_ERRORS, NULL);
13731373
if (!stream) {
13741374
return FAILURE;
13751375
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-21058 (error_log() crash with null destination and message type 3)
3+
--FILE--
4+
<?php
5+
6+
try {
7+
error_log("test", 3, null);
8+
} catch (\ValueError $e) {
9+
echo $e->getMessage(), PHP_EOL;
10+
}
11+
?>
12+
--EXPECT--
13+
Path must not be empty

0 commit comments

Comments
 (0)