From ae2150692a9a2e0878314385d03826f160e6a76a Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 5 Jan 2020 15:15:09 +0100 Subject: 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. --- NEWS | 4 ++++ ext/standard/mail.c | 2 +- ext/standard/tests/mail/bug54298.phpt | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/mail/bug54298.phpt diff --git a/NEWS b/NEWS index 08f0f5b2db..acecfa4037 100644 --- a/NEWS +++ b/NEWS @@ -49,6 +49,10 @@ PHP NEWS - Shmop: . Fixed bug #78538 (shmop memory leak). (cmb) +- Standard: + . Fixed bug #54298 (Using empty additional_headers adding extraneous CRLF). + (cmb) + 18 Dec 2019, PHP 7.3.13 - Bcmath: diff --git a/ext/standard/mail.c b/ext/standard/mail.c index ca6ca115c2..1743e6dfbd 100644 --- a/ext/standard/mail.c +++ b/ext/standard/mail.c @@ -372,7 +372,7 @@ PHP_FUNCTION(mail) extra_cmd = php_escape_shell_cmd(ZSTR_VAL(extra_cmd)); } - if (php_mail(to_r, subject_r, message, str_headers ? ZSTR_VAL(str_headers) : NULL, extra_cmd ? ZSTR_VAL(extra_cmd) : NULL)) { + 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)) { RETVAL_TRUE; } else { RETVAL_FALSE; diff --git a/ext/standard/tests/mail/bug54298.phpt b/ext/standard/tests/mail/bug54298.phpt new file mode 100644 index 0000000000..a2ab9c83ab --- /dev/null +++ b/ext/standard/tests/mail/bug54298.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #54298 (Using empty additional_headers adding extraneous CRLF) +--INI-- +sendmail_path=tee bug54298.eml >/dev/null +mail.add_x_header = Off +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) +To: someuser@example.com +Subject: testsubj + +Body part +--CLEAN-- + -- cgit v1.2.1