Check for malloc failure
authorRich Salz <rsalz@openssl.org>
Mon, 27 Nov 2017 19:11:36 +0000 (14:11 -0500)
committerRich Salz <rsalz@openssl.org>
Mon, 27 Nov 2017 19:47:42 +0000 (14:47 -0500)
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4805)

crypto/cms/cms_sd.c

index 764781688b00ae3d2c931cff7ebd0207a0b83b63..ff2d540b6a30cd6e0a9710ad8c7eff014a729a59 100644 (file)
@@ -714,8 +714,10 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
     md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm);
     if (md == NULL)
         return -1;
     md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm);
     if (md == NULL)
         return -1;
-    if (si->mctx == NULL)
-        si->mctx = EVP_MD_CTX_new();
+    if (si->mctx == NULL && (si->mctx = EVP_MD_CTX_new()) == NULL) {
+        CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY, ERR_R_MALLOC_FAILURE);
+        return -1;
+    }
     mctx = si->mctx;
     if (EVP_DigestVerifyInit(mctx, &si->pctx, md, NULL, si->pkey) <= 0)
         goto err;
     mctx = si->mctx;
     if (EVP_DigestVerifyInit(mctx, &si->pctx, md, NULL, si->pkey) <= 0)
         goto err;