From: Jonas Maebe Date: Mon, 9 Dec 2013 21:02:06 +0000 (+0100) Subject: multi_split: check for NULL when allocating parts and bpart, and for failure of sk_BI... X-Git-Tag: master-post-reformat~506 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1c4b688cb45a912d25d839f8ed6287e610352f57;p=oweals%2Fopenssl.git multi_split: check for NULL when allocating parts and bpart, and for failure of sk_BIO_push() Signed-off-by: Kurt Roeckx Reviewed-by: Rich Salz --- diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index 5cd5ef759f..171c83dbfc 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -636,21 +636,34 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) first = 1; parts = sk_BIO_new_null(); *ret = parts; + if (*ret == NULL) + return 0; while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { state = mime_bound_check(linebuf, len, bound, blen); if(state == 1) { first = 1; part++; } else if(state == 2) { - sk_BIO_push(parts, bpart); + if (!sk_BIO_push(parts, bpart)) + { + BIO_free(bpart); + return 0; + } return 1; } else if(part) { /* Strip CR+LF from linebuf */ next_eol = strip_eol(linebuf, &len, 0); if(first) { first = 0; - if(bpart) sk_BIO_push(parts, bpart); + if(bpart) + if (!sk_BIO_push(parts, bpart)) + { + BIO_free(bpart); + return 0; + } bpart = BIO_new(BIO_s_mem()); + if (bpart == NULL) + return 0; BIO_set_mem_eof_return(bpart, 0); } else if (eol) BIO_write(bpart, "\r\n", 2); @@ -659,6 +672,8 @@ static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) BIO_write(bpart, linebuf, len); } } + if (bpart != NULL) + BIO_free(bpart); return 0; }