Skip to content

Commit ae21506

Browse files
committed
Fix #54298: Using empty additional_headers adding extraneous CRLF
If the header string is empty, we pass `NULL` to `php_mail()` to avoid further checks on the string length.
1 parent 4bec59f commit ae21506

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ PHP NEWS
4949
- Shmop:
5050
. Fixed bug #78538 (shmop memory leak). (cmb)
5151

52+
- Standard:
53+
. Fixed bug #54298 (Using empty additional_headers adding extraneous CRLF).
54+
(cmb)
55+
5256
18 Dec 2019, PHP 7.3.13
5357

5458
- Bcmath:

ext/standard/mail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ PHP_FUNCTION(mail)
372372
extra_cmd = php_escape_shell_cmd(ZSTR_VAL(extra_cmd));
373373
}
374374

375-
if (php_mail(to_r, subject_r, message, str_headers ? ZSTR_VAL(str_headers) : NULL, extra_cmd ? ZSTR_VAL(extra_cmd) : NULL)) {
375+
if (php_mail(to_r, subject_r, message, str_headers && ZSTR_LEN(str_headers) ? ZSTR_VAL(str_headers) : NULL, extra_cmd ? ZSTR_VAL(extra_cmd) : NULL)) {
376376
RETVAL_TRUE;
377377
} else {
378378
RETVAL_FALSE;

ext/standard/tests/mail/bug54298.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #54298 (Using empty additional_headers adding extraneous CRLF)
3+
--INI--
4+
sendmail_path=tee bug54298.eml >/dev/null
5+
mail.add_x_header = Off
6+
--SKIPIF--
7+
<?php
8+
if (PHP_OS_FAMILY === 'Windows') die("skip Won't run on Windows");
9+
?>
10+
--FILE--
11+
<?php
12+
var_dump(mail('[email protected]', 'testsubj', 'Body part', ''));
13+
echo file_get_contents('bug54298.eml');
14+
?>
15+
--EXPECT--
16+
bool(true)
17+
18+
Subject: testsubj
19+
20+
Body part
21+
--CLEAN--
22+
<?php
23+
unlink('bug54298.eml');
24+
?>

0 commit comments

Comments
 (0)