From bab3fd592541c3c1483cda94373863f4bee87265 Mon Sep 17 00:00:00 2001 From: Chris Conlon <chris@wolfssl.com> Date: Mon, 17 Apr 2017 14:23:37 -0600 Subject: [PATCH] fix clang/scan-build warnings for PKCS7 --- wolfcrypt/src/pkcs7.c | 20 +++++++++----------- wolfcrypt/test/test.c | 8 ++++---- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index edfdf794a..fb4aab9ea 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -451,7 +451,7 @@ static int wc_PKCS7_RsaSign(PKCS7* pkcs7, byte* in, word32 inSz, ESD* esd) #endif if (pkcs7 == NULL || pkcs7->privateKey == NULL || pkcs7->rng == NULL || - in == NULL || esd == NULL || esd->encContentDigest == NULL) + in == NULL || esd == NULL) return BAD_FUNC_ARG; #ifdef WOLFSSL_SMALL_STACK @@ -500,7 +500,7 @@ static int wc_PKCS7_EcdsaSign(PKCS7* pkcs7, byte* in, word32 inSz, ESD* esd) #endif if (pkcs7 == NULL || pkcs7->privateKey == NULL || pkcs7->rng == NULL || - in == NULL || esd == NULL || esd->encContentDigest == NULL) + in == NULL || esd == NULL) return BAD_FUNC_ARG; #ifdef WOLFSSL_SMALL_STACK @@ -559,7 +559,7 @@ static int wc_PKCS7_BuildSignedAttributes(PKCS7* pkcs7, ESD* esd) PKCS7Attrib cannedAttribs[2]; word32 cannedAttribsCount; - if (pkcs7 == NULL || esd == NULL || &esd->hash == NULL) + if (pkcs7 == NULL || esd == NULL) return BAD_FUNC_ARG; hashSz = wc_HashGetDigestSize(esd->hashType); @@ -672,9 +672,8 @@ static int wc_PKCS7_BuildDigestInfo(PKCS7* pkcs7, byte* flatSignedAttribs, word32 digestInfoSeqSz, digestStrSz, algoIdSz; word32 attribSetSz; - if (pkcs7 == NULL || esd == NULL || &esd->hash == NULL || - esd->contentDigest == NULL || esd->signerDigAlgoId == NULL || - digestInfo == NULL || digestInfoSz == NULL) { + if (pkcs7 == NULL || esd == NULL || digestInfo == NULL || + digestInfoSz == NULL) { return BAD_FUNC_ARG; } @@ -764,7 +763,7 @@ static int wc_PKCS7_SignedDataBuildSignature(PKCS7* pkcs7, byte digestInfo[digestInfoSz]; #endif - if (pkcs7 == NULL || esd == NULL || esd->contentAttribsDigest == NULL) + if (pkcs7 == NULL || esd == NULL) return BAD_FUNC_ARG; #ifdef WOLFSSL_SMALL_STACK @@ -1114,7 +1113,7 @@ int wc_PKCS7_EncodeSignedData(PKCS7* pkcs7, byte* output, word32 outputSz) idx += esd->signerDigAlgoIdSz; /* SignerInfo:Attributes */ - if (pkcs7->signedAttribsSz != 0) { + if (flatSignedAttribsSz > 0) { XMEMCPY(output + idx, esd->signedAttribSet, esd->signedAttribSetSz); idx += esd->signedAttribSetSz; XMEMCPY(output + idx, flatSignedAttribs, flatSignedAttribsSz); @@ -1156,8 +1155,7 @@ static int wc_PKCS7_RsaVerify(PKCS7* pkcs7, byte* sig, int sigSz, RsaKey* key = &stack_key; #endif - if (pkcs7 == NULL || pkcs7->publicKey == NULL || - sig == NULL || hash == NULL) { + if (pkcs7 == NULL || sig == NULL || hash == NULL) { return BAD_FUNC_ARG; } @@ -1234,7 +1232,7 @@ static int wc_PKCS7_EcdsaVerify(PKCS7* pkcs7, byte* sig, int sigSz, ecc_key* key = &stack_key; #endif - if (pkcs7 == NULL || pkcs7->publicKey == NULL || sig == NULL) + if (pkcs7 == NULL || sig == NULL) return BAD_FUNC_ARG; #ifdef WOLFSSL_SMALL_STACK diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 1c413e882..50b03f5de 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -12205,7 +12205,7 @@ static int pkcs7_load_certs_keys(byte* rsaCert, word32* rsaCertSz, if (!certFile) return -203; - *rsaCertSz = fread(rsaCert, 1, *rsaCertSz, certFile); + *rsaCertSz = (word32)fread(rsaCert, 1, *rsaCertSz, certFile); fclose(certFile); #endif @@ -12226,7 +12226,7 @@ static int pkcs7_load_certs_keys(byte* rsaCert, word32* rsaCertSz, if (!keyFile) return -204; - *rsaPrivKeySz = fread(rsaPrivKey, 1, *rsaPrivKeySz, keyFile); + *rsaPrivKeySz = (word32)fread(rsaPrivKey, 1, *rsaPrivKeySz, keyFile); fclose(keyFile); #endif /* USE_CERT_BUFFERS */ @@ -12246,7 +12246,7 @@ static int pkcs7_load_certs_keys(byte* rsaCert, word32* rsaCertSz, if (!certFile) return -207; - *eccCertSz = fread(eccCert, 1, *eccCertSz, certFile); + *eccCertSz = (word32)fread(eccCert, 1, *eccCertSz, certFile); fclose(certFile); #endif /* USE_CERT_BUFFERS_256 */ @@ -12261,7 +12261,7 @@ static int pkcs7_load_certs_keys(byte* rsaCert, word32* rsaCertSz, if (!keyFile) return -208; - *eccPrivKeySz = fread(eccPrivKey, 1, *eccPrivKeySz, keyFile); + *eccPrivKeySz = (word32)fread(eccPrivKey, 1, *eccPrivKeySz, keyFile); fclose(keyFile); #endif /* USE_CERT_BUFFERS_256 */ #endif /* HAVE_ECC */