Don't ignore return value of EVP_DigestInit_ex() in md BIOs and dgst utility.
[openssl.git] / crypto / evp / bio_md.c
index c632dfb20227fec1d6d4bc22dd35267a0b10bd88..27ec62f4b55064583267072a9917426a734a257f 100644 (file)
@@ -176,10 +176,11 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
                {
        case BIO_CTRL_RESET:
                if (b->init)
-                       EVP_DigestInit_ex(ctx,ctx->digest, NULL);
+                       ret = EVP_DigestInit_ex(ctx,ctx->digest, NULL);
                else
                        ret=0;
-               ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+               if (ret > 0)
+                       ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
                break;
        case BIO_C_GET_MD:
                if (b->init)
@@ -207,8 +208,9 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
 
        case BIO_C_SET_MD:
                md=ptr;
-               EVP_DigestInit_ex(ctx,md, NULL);
-               b->init=1;
+               ret = EVP_DigestInit_ex(ctx,md, NULL);
+               if (ret > 0)
+                       b->init=1;
                break;
        case BIO_CTRL_DUP:
                dbio=ptr;