PR: 1990
[oweals/openssl.git] / crypto / evp / p5_crpt2.c
index f2e143d2a68c2e6472d9c3cd97d45ca28cfbe6f9..6bec77baf96430219eb5820049b34ed8742a2450 100644 (file)
@@ -1,5 +1,5 @@
 /* p5_crpt2.c */
-/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 1999.
  */
 /* ====================================================================
@@ -156,10 +156,15 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
        const EVP_CIPHER *cipher;
        PBKDF2PARAM *kdf = NULL;
 
+       if (param == NULL || param->type != V_ASN1_SEQUENCE ||
+           param->value.sequence == NULL) {
+               EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
+               return 0;
+       }
+
        pbuf = param->value.sequence->data;
        plen = param->value.sequence->length;
-       if(!param || (param->type != V_ASN1_SEQUENCE) ||
-                                  !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
+       if(!(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
                EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
                return 0;
        }
@@ -196,11 +201,16 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
 
        /* Now decode key derivation function */
 
+       if(!pbe2->keyfunc->parameter ||
+                (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE))
+               {
+               EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
+               goto err;
+               }
+
        pbuf = pbe2->keyfunc->parameter->value.sequence->data;
        plen = pbe2->keyfunc->parameter->value.sequence->length;
-       if(!pbe2->keyfunc->parameter ||
-                (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE) ||
-                               !(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
+       if(!(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
                EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
                goto err;
        }