coverity null pointer dereference
@@ -530,9 +530,13 @@ static int drbg_ctr_init_lengths(PROV_DRBG *drbg)
static int drbg_ctr_init(PROV_DRBG *drbg)
{
PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
- const size_t keylen = EVP_CIPHER_key_length(ctr->cipher_ctr);
+ size_t keylen;
- ctr->keylen = keylen;
+ if (ctr->cipher_ctr == NULL) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_MISSING_CIPHER);
+ return 0;
+ }
+ ctr->keylen = keylen = EVP_CIPHER_key_length(ctr->cipher_ctr);
if (ctr->ctx_ecb == NULL)
ctr->ctx_ecb = EVP_CIPHER_CTX_new();
if (ctr->ctx_ctr == NULL)
@@ -542,7 +546,6 @@ static int drbg_ctr_init(PROV_DRBG *drbg)
goto err;
}
- if (ctr->cipher_ctr != NULL) {
if (!EVP_CipherInit_ex(ctr->ctx_ecb,
ctr->cipher_ecb, NULL, NULL, NULL, 1)
|| !EVP_CipherInit_ex(ctr->ctx_ctr,
@@ -576,7 +579,6 @@ static int drbg_ctr_init(PROV_DRBG *drbg)
goto err;
}
}
- }
return drbg_ctr_init_lengths(drbg);
err:
