summaryrefslogtreecommitdiff
path: root/ext/imap/php_imap.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/imap/php_imap.c')
-rw-r--r--ext/imap/php_imap.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c
index 841ef49fcd..8f22964a5e 100644
--- a/ext/imap/php_imap.c
+++ b/ext/imap/php_imap.c
@@ -2211,6 +2211,9 @@ PHP_FUNCTION(imap_utf8)
if (dest.data) {
free(dest.data);
}
+ if (src.data) {
+ free(src.data);
+ }
if (src.data && src.data != dest.data) {
free(src.data);
}
@@ -2952,7 +2955,7 @@ PHP_FUNCTION(imap_mail_compose)
BODY *bod=NULL, *topbod=NULL;
PART *mypart=NULL, *part;
PARAMETER *param, *disp_param = NULL, *custom_headers_param = NULL, *tmp_param = NULL;
- char tmp[SENDBUFLEN + 1], *mystring=NULL, *t=NULL, *tempstring=NULL;
+ char *tmp=NULL, *mystring=NULL, *t=NULL, *tempstring=NULL;
int toppart = 0;
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &envelope, &body) == FAILURE) {
@@ -3184,7 +3187,7 @@ PHP_FUNCTION(imap_mail_compose)
disp_param->next = tmp_param;
tmp_param = disp_param;
}
- bod->parameter = disp_param;
+ bod->parameter = disp_param;
}
}
if (zend_hash_find(Z_ARRVAL_PP(data), "subtype", sizeof("subtype"), (void **) &pvalue)== SUCCESS) {
@@ -3254,6 +3257,9 @@ PHP_FUNCTION(imap_mail_compose)
}
rfc822_encode_body_7bit(env, topbod);
+
+ tmp = emalloc(SENDBUFLEN + 1);
+
rfc822_header(tmp, env, topbod);
/* add custom envelope headers */
@@ -3303,7 +3309,7 @@ PHP_FUNCTION(imap_mail_compose)
/* yucky default */
if (!cookie) {
cookie = "-";
- } else if (strlen(cookie) > (sizeof(tmp) - 2 - 2)) { /* validate cookie length -- + CRLF */
+ } else if (strlen(cookie) > (SENDBUFLEN - 2 - 2 - 2)) { /* validate cookie length -- + CRLF * 2 */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The boudary should be no longer then 4kb");
RETVAL_FALSE;
goto done;
@@ -3311,18 +3317,14 @@ PHP_FUNCTION(imap_mail_compose)
/* for each part */
do {
- t=tmp;
- /* build cookie */
- sprintf(t, "--%s%s", cookie, CRLF);
-
+ t = tmp;
+
/* append mini-header */
+ *t = '\0';
rfc822_write_body_header(&t, &part->body);
- /* write terminating blank line */
- strcat(t, CRLF);
-
/* output cookie, mini-header, and contents */
- spprintf(&tempstring, 0, "%s%s", mystring, tmp);
+ spprintf(&tempstring, 0, "%s--%s%s%s%s", mystring, cookie, CRLF, tmp, CRLF);
efree(mystring);
mystring=tempstring;
@@ -3334,13 +3336,13 @@ PHP_FUNCTION(imap_mail_compose)
} while ((part = part->next)); /* until done */
/* output trailing cookie */
- spprintf(&tempstring, 0, "%s--%s--%s", mystring, tmp, CRLF);
+ spprintf(&tempstring, 0, "%s--%s--%s", mystring, cookie, CRLF);
efree(mystring);
mystring=tempstring;
} else if (bod) {
- spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data, CRLF);
- efree(mystring);
- mystring=tempstring;
+ spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data, CRLF);
+ efree(mystring);
+ mystring=tempstring;
} else {
efree(mystring);
RETVAL_FALSE;
@@ -3349,6 +3351,9 @@ PHP_FUNCTION(imap_mail_compose)
RETVAL_STRING(tempstring, 0);
done:
+ if (tmp) {
+ efree(tmp);
+ }
mail_free_body(&topbod);
mail_free_envelope(&env);
}
@@ -3889,7 +3894,7 @@ static void _php_imap_parse_address (ADDRESS *addresslist, char **fulladdress, z
addresstmp = addresslist;
if ((len = _php_imap_address_size(addresstmp))) {
- tmpstr = (char *) malloc(len + 1);
+ tmpstr = (char *) pemalloc(len + 1, 1);
tmpstr[0] = '\0';
rfc822_write_address(tmpstr, addresstmp);
*fulladdress = tmpstr;
@@ -4310,7 +4315,7 @@ static char *php_mail_gets(readfn_t f, void *stream, unsigned long size, GETS_DA
}
return NULL;
} else {
- char *buf = malloc(size + 1);
+ char *buf = pemalloc(size + 1, 1);
if (f(stream, size, buf)) {
buf[size] = '\0';