Skip to content

Commit 51b1aa1

Browse files
jordikroondevnexen
authored andcommitted
Fix GH-20858: null pointer dereference in php_mail_detect_multiple_crlf via error_log
close GH-20862
1 parent 1791578 commit 51b1aa1

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ PHP NEWS
3131
. Fixed bug GH-20483 (ASAN stack overflow with fiber.stack_size INI
3232
small value). (David Carlier)
3333

34+
- Mail:
35+
. Fixed bug GH-20862 (null pointer dereference in
36+
php_mail_detect_multiple_crlf via error_log (jordikroon)
37+
3438
- Mbstring:
3539
. ini_set() with mbstring.detect_order changes the order of mb_detect_order
3640
as intended, since mbstring.detect_order is an INI_ALL setting. (tobee94)

ext/standard/basic_functions.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,11 +1349,17 @@ PHPAPI zend_result _php_error_log(int opt_err, const zend_string *message, const
13491349
{
13501350
php_stream *stream = NULL;
13511351
size_t nbytes;
1352+
const char *hdrs = NULL;
13521353

13531354
switch (opt_err)
13541355
{
13551356
case 1: /*send an email */
1356-
if (!php_mail(ZSTR_VAL(opt), "PHP error_log message", ZSTR_VAL(message), ZSTR_VAL(headers), NULL)) {
1357+
if (!opt) {
1358+
return FAILURE;
1359+
}
1360+
1361+
hdrs = headers ? ZSTR_VAL(headers) : NULL;
1362+
if (!php_mail(ZSTR_VAL(opt), "PHP error_log message", ZSTR_VAL(message), hdrs, NULL)) {
13571363
return FAILURE;
13581364
}
13591365
break;

tests/basic/gh20858.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
GH-20858 Null pointer dereference in php_mail_detect_multiple_crlf via error_log
3+
--INI--
4+
sendmail_path={MAIL:{PWD}/gh20858.eml}
5+
mail.add_x_header=off
6+
--FILE--
7+
<?php
8+
9+
$headers = "From: test <[email protected]>\n";
10+
$headers .= "Cc: test <[email protected]>\n";
11+
$headers .= 'X-Mailer: PHP/' . phpversion();
12+
13+
// Send mail with nothing set
14+
var_dump(error_log("Error message", 1, null));
15+
16+
// Send mail with destination set
17+
var_dump(error_log("Error message with dest", 1, "[email protected]", null));
18+
19+
// Send mail with custom headers and no mailer to
20+
var_dump(error_log("Error message cust headers", 1, null, $headers));
21+
22+
// Send mail with destination set + custom headers
23+
var_dump(error_log("Error message with both", 1, "[email protected]", $headers));
24+
?>
25+
--CLEAN--
26+
<?php
27+
$filePath = __DIR__ . "/gh20858.eml";
28+
if (file_exists($filePath)) {
29+
unlink($filePath);
30+
}
31+
?>
32+
--EXPECTF--
33+
bool(false)
34+
bool(true)
35+
bool(false)
36+
bool(true)

0 commit comments

Comments
 (0)