summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-01-05 15:15:09 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2020-01-06 14:47:23 +0100
commitae2150692a9a2e0878314385d03826f160e6a76a (patch)
tree274a226d26c80d0b5cdc035d319af923e9579391
parent4bec59f1751d9d1e302465b68cceffb8df93a7be (diff)
downloadphp-git-ae2150692a9a2e0878314385d03826f160e6a76a.tar.gz
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.
-rw-r--r--NEWS4
-rw-r--r--ext/standard/mail.c2
-rw-r--r--ext/standard/tests/mail/bug54298.phpt24
3 files changed, 29 insertions, 1 deletions
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--
+<?php
+if (PHP_OS_FAMILY === 'Windows') die("skip Won't run on Windows");
+?>
+--FILE--
+<?php
+var_dump(mail('someuser@example.com', 'testsubj', 'Body part', ''));
+echo file_get_contents('bug54298.eml');
+?>
+--EXPECT--
+bool(true)
+To: someuser@example.com
+Subject: testsubj
+
+Body part
+--CLEAN--
+<?php
+unlink('bug54298.eml');
+?>