Skip to content

Commit 2f2bee1

Browse files
committed
fix label followed by a declaration and add more tests
1 parent 93f25d8 commit 2f2bee1

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

ext/standard/basic_functions.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,11 +1350,15 @@ PHPAPI zend_result _php_error_log(int opt_err, const zend_string *message, const
13501350
php_stream *stream = NULL;
13511351
size_t nbytes;
13521352

1353+
const char *to = NULL;
1354+
const char *hdrs = NULL;
1355+
13531356
switch (opt_err)
13541357
{
13551358
case 1: /*send an email */
1356-
const char *to = opt ? ZSTR_VAL(opt) : NULL;
1357-
const char *hdrs = headers ? ZSTR_VAL(headers) : NULL;
1359+
to = opt ? ZSTR_VAL(opt) : NULL;
1360+
hdrs = headers ? ZSTR_VAL(headers) : NULL;
1361+
13581362
if (!php_mail(to, "PHP error_log message", ZSTR_VAL(message), hdrs, NULL)) {
13591363
return FAILURE;
13601364
}

tests/basic/gh20858_headers.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-20858 Null pointer dereference in php_mail_detect_multiple_crlf via error_log
3+
--FILE--
4+
<?php
5+
6+
$headers = "From: test <[email protected]>\n";
7+
$headers .= "Cc: test <[email protected]>\n";
8+
$headers .= 'X-Mailer: PHP/' . phpversion();
9+
10+
// Send mail with destination set
11+
error_log(0, 1, "[email protected]>", null);
12+
13+
// Send mail with custom headers
14+
error_log(0, 1, null, $headers);
15+
16+
// Send mail with destination set + custom headers
17+
error_log(0, 1, "[email protected]>", $headers);
18+
?>
19+
--EXPECTF--

0 commit comments

Comments
 (0)