]> granicus.if.org Git - php/commitdiff
Fix #54298: Using empty additional_headers adding extraneous CRLF
authorChristoph M. Becker <cmbecker69@gmx.de>
Sun, 5 Jan 2020 14:15:09 +0000 (15:15 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 6 Jan 2020 13:47:23 +0000 (14:47 +0100)
If the header string is empty, we pass `NULL` to `php_mail()` to avoid
further checks on the string length.

NEWS
ext/standard/mail.c
ext/standard/tests/mail/bug54298.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 08f0f5b2db46a2c920abe67808d735ec15094037..acecfa4037639427ef4e51012933fc154835c923 100644 (file)
--- 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:
index ca6ca115c2e5f58baf9cad3f73aab1d8d72bca2e..1743e6dfbd87537f2e878fc1a3008d1e8db703ba 100644 (file)
@@ -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 (file)
index 0000000..a2ab9c8
--- /dev/null
@@ -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');
+?>