Skip to content

Commit 11f4730

Browse files
committed
fix null pointer dereference in php_mail_detect_multiple_crlf via error_log
1 parent cb63e4f commit 11f4730

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

ext/standard/basic_functions.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,10 +1350,16 @@ 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-
if (!php_mail(ZSTR_VAL(opt), "PHP error_log message", ZSTR_VAL(message), ZSTR_VAL(headers), NULL)) {
1359+
to = opt ? ZSTR_VAL(opt) : NULL;
1360+
hdrs = headers ? ZSTR_VAL(headers) : NULL;
1361+
1362+
if (!php_mail(to, "PHP error_log message", ZSTR_VAL(message), hdrs, NULL)) {
13571363
return FAILURE;
13581364
}
13591365
break;

tests/basic/gh20858.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-20858 Null pointer dereference in php_mail_detect_multiple_crlf via error_log
3+
--INI--
4+
sendmail_path="cat > /tmp/php_test_gh20878.out"
5+
mail.force_extra_parameters="-n"
6+
mail.add_x_header = Off
7+
--SKIPIF--
8+
<?php
9+
if(substr(PHP_OS, 0, 3) == "WIN")
10+
die("skip Won't run on Windows");
11+
?>
12+
--FILE--
13+
<?php
14+
15+
$headers = "From: test <mail@domain.tld>\n";
16+
$headers .= "Cc: test <mail@domain.tld>\n";
17+
$headers .= 'X-Mailer: PHP/' . phpversion();
18+
19+
// Send mail with nothing set
20+
var_dump(error_log("Error message", 1, null));
21+
22+
// Send mail with destination set
23+
var_dump(error_log("Error message with dest", 1, "default@domain.tld>", null));
24+
25+
// Send mail with custom headers
26+
var_dump(error_log("Error message cust headers", 1, null, $headers));
27+
28+
// Send mail with destination set + custom headers
29+
var_dump(error_log("Error message with both", 1, "default@domain.tld>", $headers));
30+
?>
31+
--EXPECTF--
32+
bool(true)
33+
bool(true)
34+
bool(true)
35+
bool(true)

0 commit comments

Comments
 (0)