summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-04-02 13:06:19 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-04-02 14:51:14 +0200
commit6983ae751cd301886c966b84367fc7aaa1273b2d (patch)
tree508f4bf502732ed17c65b998c3380398ff56ec1d
parent737f7dd8f64d8306eccc2f7f4a611a8bdfe88086 (diff)
downloadphp-git-6983ae751cd301886c966b84367fc7aaa1273b2d.tar.gz
Fix #47983: mixed LF and CRLF line endings in mail()
Email headers are supposed to be separated with CRLF. Period.
-rw-r--r--NEWS1
-rw-r--r--ext/standard/mail.c10
-rw-r--r--ext/standard/tests/mail/bug47983.phpt17
3 files changed, 23 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 83ef93e59d..24608bdd5d 100644
--- a/NEWS
+++ b/NEWS
@@ -125,6 +125,7 @@ PHP NEWS
is the last char). (Islam Israfilov)
. Fixed bug #75902 (str_replace should warn when misused with nested arrays).
(Nikita)
+ . Fixed bug #47983 (mixed LF and CRLF line endings in mail()). (cmb)
. Made quoting of cmd execution functions consistent. (cmb)
- tidy:
diff --git a/ext/standard/mail.c b/ext/standard/mail.c
index d08325c3fa..096f432c9a 100644
--- a/ext/standard/mail.c
+++ b/ext/standard/mail.c
@@ -486,7 +486,7 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
f = php_basename(tmp, strlen(tmp), NULL, 0);
if (headers != NULL && *headers) {
- spprintf(&hdr, 0, "X-PHP-Originating-Script: " ZEND_LONG_FMT ":%s\n%s", php_getuid(), ZSTR_VAL(f), headers);
+ spprintf(&hdr, 0, "X-PHP-Originating-Script: " ZEND_LONG_FMT ":%s\r\n%s", php_getuid(), ZSTR_VAL(f), headers);
} else {
spprintf(&hdr, 0, "X-PHP-Originating-Script: " ZEND_LONG_FMT ":%s", php_getuid(), ZSTR_VAL(f));
}
@@ -559,12 +559,12 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
MAIL_RET(0);
}
#endif
- fprintf(sendmail, "To: %s\n", to);
- fprintf(sendmail, "Subject: %s\n", subject);
+ fprintf(sendmail, "To: %s\r\n", to);
+ fprintf(sendmail, "Subject: %s\r\n", subject);
if (hdr != NULL) {
- fprintf(sendmail, "%s\n", hdr);
+ fprintf(sendmail, "%s\r\n", hdr);
}
- fprintf(sendmail, "\n%s\n", message);
+ fprintf(sendmail, "\r\n%s\r\n", message);
ret = pclose(sendmail);
#if PHP_SIGCHILD
diff --git a/ext/standard/tests/mail/bug47983.phpt b/ext/standard/tests/mail/bug47983.phpt
new file mode 100644
index 0000000000..f908ca6947
--- /dev/null
+++ b/ext/standard/tests/mail/bug47983.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #47983 (mixed LF and CRLF line endings in mail())
+--INI--
+sendmail_path={MAIL:bug47983.out}
+--FILE--
+<?php
+var_dump(mail('user@example.com', 'Test Subject', 'A Message', 'KHeaders'));
+$mail = file_get_contents('bug47983.out');
+var_dump(preg_match_all('/(?<!\r)\n/', $mail));
+?>
+--CLEAN--
+<?php
+unlink('bug47983.out');
+?>
+--EXPECT--
+bool(true)
+int(0)