From: Pauli Date: Sun, 6 Jun 2021 23:39:55 +0000 (+1000) Subject: pkcs12: fix Coverity 1485667 logically dead code X-Git-Tag: openssl-3.0.0-beta1~145 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9428977994921d23b6aabc047298db3c55867709;p=thirdparty%2Fopenssl.git pkcs12: fix Coverity 1485667 logically dead code Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15635) --- diff --git a/crypto/pkcs12/p12_mutl.c b/crypto/pkcs12/p12_mutl.c index 88655651a0e..afdb8d688ba 100644 --- a/crypto/pkcs12/p12_mutl.c +++ b/crypto/pkcs12/p12_mutl.c @@ -249,23 +249,22 @@ int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen, return 0; } } - if (!saltlen) + if (saltlen == 0) saltlen = PKCS12_SALT_LEN; - if (saltlen < 0) + else if (saltlen < 0) return 0; if ((p12->mac->salt->data = OPENSSL_malloc(saltlen)) == NULL) { ERR_raise(ERR_LIB_PKCS12, ERR_R_MALLOC_FAILURE); return 0; } p12->mac->salt->length = saltlen; - if (!salt) { - if (saltlen < 0) - return 0; + if (salt == NULL) { if (RAND_bytes_ex(p12->authsafes->ctx.libctx, p12->mac->salt->data, (size_t)saltlen, 0) <= 0) return 0; - } else + } else { memcpy(p12->mac->salt->data, salt, saltlen); + } X509_SIG_getm(p12->mac->dinfo, &macalg, NULL); if (!X509_ALGOR_set0(macalg, OBJ_nid2obj(EVP_MD_get_type(md_type)), V_ASN1_NULL, NULL)) {