|
31 | 31 | #include "php_ini.h" |
32 | 32 |
|
33 | 33 | #include "php_win32_globals.h" |
| 34 | +#include "../Zend/zend_string.h" |
34 | 35 |
|
35 | 36 | #include "ext/pcre/php_pcre.h" |
36 | 37 | #include "ext/standard/php_string.h" |
@@ -112,7 +113,7 @@ static const char *ErrorMessages[] = |
112 | 113 | #define PHP_WIN32_MAIL_DOT_REPLACE "\n.." |
113 | 114 |
|
114 | 115 | static int SendText(char *RPath, const char *Subject, const char *mailTo, const char *data, |
115 | | - const zend_string *headers, zend_string *headers_lc, char **error_message); |
| 116 | + zend_string *headers, zend_string *headers_lc, char **error_message); |
116 | 117 | static int MailConnect(); |
117 | 118 | static int PostHeader(char *RPath, const char *Subject, const char *mailTo, char *xheaders); |
118 | 119 | static bool Post(LPCSTR msg); |
@@ -387,14 +388,14 @@ static char *find_address(char *list, char **state) |
387 | 388 | // History: |
388 | 389 | //********************************************************************* |
389 | 390 | static int SendText(char *RPath, const char *Subject, const char *mailTo, const char *data, |
390 | | - const zend_string *headers, zend_string *headers_lc, char **error_message) |
| 391 | + zend_string *headers, zend_string *headers_lc, char **error_message) |
391 | 392 | { |
392 | 393 | int res; |
393 | 394 | char *p; |
394 | 395 | char *tempMailTo, *token, *token_state; |
395 | 396 | const char *pos1, *pos2; |
396 | 397 | char *server_response = NULL; |
397 | | - char *stripped_header = NULL; |
| 398 | + zend_string *stripped_header = NULL; |
398 | 399 | zend_string *data_cln; |
399 | 400 |
|
400 | 401 | /* check for NULL parameters */ |
@@ -565,35 +566,36 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, const |
565 | 566 |
|
566 | 567 | /* Now that we've identified that we've a Bcc list, |
567 | 568 | remove it from the current header. */ |
568 | | - stripped_header = ecalloc(1, ZSTR_LEN(headers)); |
569 | 569 | /* headers = point to string start of header |
570 | 570 | pos1 = pointer IN headers where the Bcc starts |
571 | 571 | '4' = Length of the characters 'bcc:' |
572 | 572 | Because we've added +4 above for parsing the Emails |
573 | 573 | we've to subtract them here. */ |
574 | | - memcpy(stripped_header, ZSTR_VAL(headers), pos1 - ZSTR_VAL(headers) - 4); |
| 574 | + size_t header_length_prior_to_bcc = pos1 - ZSTR_VAL(headers) - 4; |
575 | 575 | if (pos1 != pos2) { |
576 | 576 | /* if pos1 != pos2 , pos2 points to the rest of the headers. |
577 | 577 | Since pos1 != pos2 if "\r\n" was found, we know those characters |
578 | 578 | are there and so we jump over them (else we would generate a new header |
579 | 579 | which would look like "\r\n\r\n". */ |
580 | | - memcpy(stripped_header + (pos1 - ZSTR_VAL(headers) - 4), pos2 + 2, strlen(pos2) - 2); |
| 580 | + stripped_header = zend_string_concat2(ZSTR_VAL(headers), header_length_prior_to_bcc, pos2 + 2, strlen(pos2) - 2); |
| 581 | + } else { |
| 582 | + stripped_header = zend_string_truncate(headers, header_length_prior_to_bcc, false); |
581 | 583 | } |
582 | 584 | } else { |
583 | 585 | /* Simplify the code that we create a copy of stripped_header no matter if |
584 | | - we actually strip something or not. So we've a single efree() later. */ |
585 | | - stripped_header = estrndup(ZSTR_VAL(headers), ZSTR_LEN(headers)); |
| 586 | + we actually strip something or not. So we've a single zend_string_release() later. */ |
| 587 | + stripped_header = zend_string_copy(headers); |
586 | 588 | } |
587 | 589 | } |
588 | 590 |
|
589 | 591 | /* send message header */ |
590 | 592 | if (Subject == NULL) { |
591 | | - res = PostHeader(RPath, "No Subject", mailTo, stripped_header); |
| 593 | + res = PostHeader(RPath, "No Subject", mailTo, stripped_header ? ZSTR_VAL(stripped_header) : NULL); |
592 | 594 | } else { |
593 | | - res = PostHeader(RPath, Subject, mailTo, stripped_header); |
| 595 | + res = PostHeader(RPath, Subject, mailTo, stripped_header ? ZSTR_VAL(stripped_header) : NULL); |
594 | 596 | } |
595 | 597 | if (stripped_header) { |
596 | | - efree(stripped_header); |
| 598 | + zend_string_release_ex(stripped_header, false); |
597 | 599 | } |
598 | 600 | if (res != SUCCESS) { |
599 | 601 | return (res); |
|
0 commit comments