bio: improve error checking fixing coverity 1485659 & 1485665
authorPauli <pauli@openssl.org>
Sun, 6 Jun 2021 23:20:16 +0000 (09:20 +1000)
committerPauli <pauli@openssl.org>
Tue, 8 Jun 2021 09:32:17 +0000 (19:32 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15635)

crypto/evp/bio_ok.c

index 97641d11d1de765dc575a405863d64d073aed662..97e67fcb68141a94ff76ab415e5c7ce312ce7bad 100644 (file)
@@ -483,9 +483,11 @@ static int sig_in(BIO *b)
     void *md_data;
 
     ctx = BIO_get_data(b);
-    md = ctx->md;
+    if ((md = ctx->md) == NULL)
+        goto berr;
     digest = EVP_MD_CTX_get0_md(md);
-    md_size = EVP_MD_get_size(digest);
+    if ((md_size = EVP_MD_get_size(digest)) < 0)
+        goto berr;
     md_data = EVP_MD_CTX_get0_md_data(md);
 
     if ((int)(ctx->buf_len - ctx->buf_off) < 2 * md_size)
@@ -562,6 +564,8 @@ static int block_in(BIO *b)
     ctx = BIO_get_data(b);
     md = ctx->md;
     md_size = EVP_MD_get_size(EVP_MD_CTX_get0_md(md));
+    if (md_size < 0)
+        goto berr;
 
     assert(sizeof(tl) >= OK_BLOCK_BLOCK); /* always true */
     tl = ctx->buf[0];