]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - crypto/pkcs7/pk7_doit.c
CMS and PKCS7: fix handlling of EVP_PKEY_get_size() failure
[thirdparty/openssl.git] / crypto / pkcs7 / pk7_doit.c
index 43ea2a9b60f9ba534b9371a54b7c6f82e2ecada4..c753a0880b14f5be019d3f12dd4aa93b42bc52f3 100644 (file)
@@ -834,10 +834,9 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
                     goto err;
             } else {
                 unsigned char *abuf = NULL;
-                unsigned int abuflen;
-                abuflen = EVP_PKEY_get_size(si->pkey);
-                abuf = OPENSSL_malloc(abuflen);
-                if (abuf == NULL)
+                unsigned int abuflen = EVP_PKEY_get_size(si->pkey);
+
+                if (abuflen == 0 || (abuf = OPENSSL_malloc(abuflen)) == NULL)
                     goto err;
 
                 if (!EVP_SignFinal_ex(ctx_tmp, abuf, &abuflen, si->pkey,