dev_crypto_md5_copy: return error if allocating to_md->data fails
[oweals/openssl.git] / crypto / evp / evp_pbe.c
index 92bd7ca066400a1ca9f8ec0c662148597ee28c0b..596969594863b4b871a47215c0566ad22831a73d 100644 (file)
@@ -179,12 +179,26 @@ int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
        if (cipher_nid == -1)
                cipher = NULL;
        else
+               {
                cipher = EVP_get_cipherbynid(cipher_nid);
+               if (!cipher)
+                       {
+                       EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_CIPHER);
+                       return 0;
+                       }
+               }
 
        if (md_nid == -1)
                md = NULL;
        else
+               {
                md = EVP_get_digestbynid(md_nid);
+               if (!md)
+                       {
+                       EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_DIGEST);
+                       return 0;
+                       }
+               }
 
        if (!keygen(ctx, pass, passlen, param, cipher, md, en_de))
                {
@@ -245,7 +259,7 @@ int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
        {
        int cipher_nid, md_nid;
        if (cipher)
-               cipher_nid = EVP_CIPHER_type(cipher);
+               cipher_nid = EVP_CIPHER_nid(cipher);
        else
                cipher_nid = -1;
        if (md)