diff options
author | Jonas Maebe <jonas.maebe@elis.ugent.be> | 2013-12-09 22:02:06 +0100 |
---|---|---|
committer | Kurt Roeckx <kurt@roeckx.be> | 2014-08-15 22:37:48 +0200 |
commit | 1c4b688cb45a912d25d839f8ed6287e610352f57 (patch) | |
tree | f5b56b71530a221622f110d0f5c743bc95e3a74f | |
parent | bd4acbc70e5e224e89f23ac0f8f811af816c8b27 (diff) |
multi_split: check for NULL when allocating parts and bpart, and for failure of sk_BIO_push()
Signed-off-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
-rw-r--r-- | crypto/asn1/asn_mime.c | 19 |
1 files changed, 17 insertions, 2 deletions
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; } |