mime_hdr_addparam: free tmpname, tmpval and mparam on error path, and check whether sk_MIME_PARAM_push succeeds

Signed-off-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
This commit is contained in:
Jonas Maebe 2013-12-03 17:11:48 +01:00 committed by Kurt Roeckx
parent 15297d962c
commit 8957278869

View File

@ -861,12 +861,12 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
{ {
char *tmpname, *tmpval, *p; char *tmpname=NULL, *tmpval=NULL, *p;
int c; int c;
MIME_PARAM *mparam; MIME_PARAM *mparam=NULL;
if(name) { if(name) {
tmpname = BUF_strdup(name); tmpname = BUF_strdup(name);
if(!tmpname) return 0; if(!tmpname) goto err;
for(p = tmpname ; *p; p++) { for(p = tmpname ; *p; p++) {
c = (unsigned char)*p; c = (unsigned char)*p;
if(isupper(c)) { if(isupper(c)) {
@ -874,18 +874,27 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
*p = c; *p = c;
} }
} }
} else tmpname = NULL; }
if(value) { if(value) {
tmpval = BUF_strdup(value); tmpval = BUF_strdup(value);
if(!tmpval) return 0; if(!tmpval) goto err;
} else tmpval = NULL; }
/* Parameter values are case sensitive so leave as is */ /* Parameter values are case sensitive so leave as is */
mparam = (MIME_PARAM *) OPENSSL_malloc(sizeof(MIME_PARAM)); mparam = (MIME_PARAM *) OPENSSL_malloc(sizeof(MIME_PARAM));
if(!mparam) return 0; if(!mparam) goto err;
mparam->param_name = tmpname; mparam->param_name = tmpname;
mparam->param_value = tmpval; mparam->param_value = tmpval;
sk_MIME_PARAM_push(mhdr->params, mparam); if (!sk_MIME_PARAM_push(mhdr->params, mparam))
goto err;
return 1; return 1;
err:
if (tmpname != NULL)
OPENSSL_free(tmpname);
if (tmpval != NULL)
OPENSSL_free(tmpval);
if (mparam != NULL)
OPENSSL_free(mparam);
return 0;
} }
static int mime_hdr_cmp(const MIME_HEADER * const *a, static int mime_hdr_cmp(const MIME_HEADER * const *a,