Improve error handling in pk7_doit
authorMatt Caswell <matt@openssl.org>
Mon, 12 Mar 2018 13:56:34 +0000 (13:56 +0000)
committerMatt Caswell <matt@openssl.org>
Mon, 12 Mar 2018 19:18:34 +0000 (19:18 +0000)
If a mem allocation failed we would ignore it. This commit fixes it to
always check.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5596)

(cherry picked from commit 4718f449a3ecd5efac62b22d0fa9a759a7895dbc)

crypto/pkcs7/pk7_doit.c

index 6cf8253bc23857e7c34dfa36af17622c4c10f84e..6a463680d7ecc0ca9a95d2cff8e5ebd768ae4cdb 100644 (file)
@@ -375,16 +375,18 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
     }
 
     if (bio == NULL) {
-        if (PKCS7_is_detached(p7))
+        if (PKCS7_is_detached(p7)) {
             bio = BIO_new(BIO_s_null());
-        else if (os && os->length > 0)
+        } else if (os && os->length > 0) {
             bio = BIO_new_mem_buf(os->data, os->length);
-        if (bio == NULL) {
+        } else {
             bio = BIO_new(BIO_s_mem());
             if (bio == NULL)
                 goto err;
             BIO_set_mem_eof_return(bio, 0);
         }
+        if (bio == NULL)
+            goto err;
     }
     if (out)
         BIO_push(out, bio);