Fix bug #70145 From field incorrectly parsed from headers

This commit is contained in:
Anatol Belski 2015-08-19 11:05:35 +02:00
parent 7f4ae19c80
commit 0562ec85df

View file

@ -241,25 +241,46 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
RPath = estrdup(mailRPath); RPath = estrdup(mailRPath);
} else if (INI_STR("sendmail_from")) { } else if (INI_STR("sendmail_from")) {
RPath = estrdup(INI_STR("sendmail_from")); RPath = estrdup(INI_STR("sendmail_from"));
} else if ( headers_lc && } else if (headers_lc) {
(pos1 = strstr(headers_lc->val, "from:")) && int found = 0;
((pos1 == headers_lc->val) || (*(pos1-1) == '\n')) char *lookup = headers_lc->val;
) {
/* Real offset is memaddress from the original headers + difference of while (lookup) {
* string found in the lowercase headrs + 5 characters to jump over pos1 = strstr(lookup, "from:");
* the from: */
pos1 = headers + (pos1 - headers_lc->val) + 5; if (!pos1) {
if (NULL == (pos2 = strstr(pos1, "\r\n"))) { break;
RPath = estrndup(pos1, strlen(pos1)); } else if (pos1 != headers_lc->val && *(pos1-1) != '\n') {
} else { if (strlen(pos1) >= sizeof("from:")) {
RPath = estrndup(pos1, pos2 - pos1); lookup = pos1 + sizeof("from:");
continue;
} else {
break;
}
}
found = 1;
/* Real offset is memaddress from the original headers + difference of
* string found in the lowercase headrs + 5 characters to jump over
* the from: */
pos1 = headers + (pos1 - lookup) + 5;
if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
RPath = estrndup(pos1, strlen(pos1));
} else {
RPath = estrndup(pos1, pos2 - pos1);
}
break;
} }
} else {
if (headers_lc) { if (!found) {
zend_string_free(headers_lc); if (headers_lc) {
zend_string_free(headers_lc);
}
*error = W32_SM_SENDMAIL_FROM_NOT_SET;
return FAILURE;
} }
*error = W32_SM_SENDMAIL_FROM_NOT_SET;
return FAILURE;
} }
/* attempt to connect with mail host */ /* attempt to connect with mail host */