com php-src: Fixed bug #74005 mail.add_x_header causes RFC-breaking lone line feed: win32/sendmail. c

[email protected] (Anatol Belski)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    ec43a11581f457bd252d98e948d7a0531b4fdfc2
Author:    Anatol Belski <[email protected]>         Wed, 1 Feb 2017 12:36:14 +0100
Parents:   d9ca5d963720654f11b52beccf7d268f7813e648
Branches:  PHP-7.0 PHP-7.1 master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=ec43a11581f457bd252d98e948d7a0531b4fdfc2

Log:
Fixed bug #74005 mail.add_x_header causes RFC-breaking lone line feed

Bugs:
https://bugs.php.net/74005

Changed paths:
  M  win32/sendmail.c


Diff:
diff --git a/win32/sendmail.c b/win32/sendmail.c
index bdeff31..5473a19 100644
--- a/win32/sendmail.c
+++ b/win32/sendmail.c
@@ -208,7 +208,7 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
 {
 	int ret;
 	char *RPath = NULL;
-	zend_string *headers_lc = NULL; /* headers_lc is only created if we've a header at all */
+	zend_string *headers_lc = NULL, *headers_trim = NULL; /* headers_lc is only created if we've a header at all */
 	char *pos1 = NULL, *pos2 = NULL;
 
 	if (host == NULL) {
@@ -226,16 +226,14 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
 		size_t i;
 
 		/* Use PCRE to trim the header into the right format */
-		if (NULL == (headers_lc = php_win32_mail_trim_header(headers))) {
+		if (NULL == (headers_trim = php_win32_mail_trim_header(headers))) {
 			*error = W32_SM_PCRE_ERROR;
 			return FAILURE;
 		}
 
 		/* Create a lowercased header for all the searches so we're finally case
 		 * insensitive when searching for a pattern. */
-		for (i = 0; i < headers_lc->len; i++) {
-			headers_lc->val[i] = tolower(headers_lc->val[i]);
-		}
+		headers_lc = zend_string_tolower(headers_trim);
 	}
 
 	/* Fall back to sendmail_from php.ini setting */
@@ -292,6 +290,7 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
 			efree(RPath);
 		}
 		if (headers) {
+			zend_string_free(headers_trim);
 			zend_string_free(headers_lc);
 		}
 		/* 128 is safe here, the specifier in snprintf isn't longer than that */
@@ -304,12 +303,13 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
 			PW32G(mail_host), !INI_INT("smtp_port") ? 25 : INI_INT("smtp_port"));
 		return FAILURE;
 	} else {
-		ret = SendText(RPath, Subject, mailTo, mailCc, mailBcc, data, headers, headers_lc->val, error_message);
+		ret = SendText(RPath, Subject, mailTo, mailCc, mailBcc, data, headers_trim->val, headers_lc->val, error_message);
 		TSMClose();
 		if (RPath) {
 			efree(RPath);
 		}
 		if (headers) {
+			zend_string_free(headers_trim);
 			zend_string_free(headers_lc);
 		}
 		if (ret != SUCCESS) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.