diff --git a/src/internal.c b/src/internal.c index e230283c7..f4d6ba5d6 100644 --- a/src/internal.c +++ b/src/internal.c @@ -3368,7 +3368,7 @@ void InitX509(WOLFSSL_X509* x509, int dynamicFlag, void* heap) x509->dynamicMemory = (byte)dynamicFlag; #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) x509->refCount = 1; - wc_InitMutex(&x509->refMutex); + (void)wc_InitMutex(&x509->refMutex); #endif } diff --git a/src/tls.c b/src/tls.c index e982ad425..0aa7ebf2f 100644 --- a/src/tls.c +++ b/src/tls.c @@ -2617,7 +2617,7 @@ static int TLSX_TCA_Parse(WOLFSSL* ssl, const byte* input, word16 length, return BUFFER_ERROR; ato16(input + offset, &idSz); offset += OPAQUE16_LEN; - if (offset + idSz > length) + if (idSz > length - offset) return BUFFER_ERROR; id = input + offset; offset += idSz; diff --git a/src/tls13.c b/src/tls13.c index 2cd37050f..fe23e7876 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -4009,7 +4009,7 @@ static int DoTls13SupportedVersions(WOLFSSL* ssl, const byte* input, word32 i, return BUFFER_ERROR; ato16(&input[i], &totalExtSz); i += OPAQUE16_LEN; - if (i + totalExtSz != helloSz) + if (totalExtSz != helloSz - i) return BUFFER_ERROR; /* Need to negotiate version first. */ diff --git a/wolfcrypt/src/pkcs12.c b/wolfcrypt/src/pkcs12.c index fca9d6d58..507a3c270 100644 --- a/wolfcrypt/src/pkcs12.c +++ b/wolfcrypt/src/pkcs12.c @@ -767,6 +767,10 @@ int wc_i2d_PKCS12(WC_PKCS12* pkcs12, byte** der, int* derSz) word32 tmpIdx = 0; byte ar[MAX_LENGTH_SZ + 2]; tmpSz = SetShortInt(ar, &tmpIdx, mac->itt, MAX_LENGTH_SZ + 2); + if (tmpSz < 0) { + WOLFSSL_MSG("Error returned by SetShortInt"); + return tmpSz; + } XMEMCPY(&sdBuf[idx], ar, tmpSz); } diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index 0b0626f5d..a8233e06a 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -3430,8 +3430,8 @@ static int wc_PKCS7_VerifyContentMessageDigest(PKCS7* pkcs7, const byte* hashBuf, word32 hashSz) { - int ret = 0, innerAttribSz = 0; - word32 digestSz = 0, idx = 0; + int ret = 0, digestSz = 0, innerAttribSz = 0; + word32 idx = 0; byte* digestBuf = NULL; #ifdef WOLFSSL_SMALL_STACK byte* digest = NULL; @@ -3502,17 +3502,20 @@ static int wc_PKCS7_VerifyContentMessageDigest(PKCS7* pkcs7, digestBuf = digest; digestSz = wc_HashGetDigestSize(hashType); - + if (digestSz < 0) { + WOLFSSL_MSG("Invalid hash type"); + return digestSz; + } } else { /* user passed in pre-computed hash */ digestBuf = (byte*)hashBuf; - digestSz = hashSz; + digestSz = (int)hashSz; } /* compare generated to hash in messageDigest attribute */ - if ((innerAttribSz != (int)digestSz) || - (XMEMCMP(attrib->value + idx, digestBuf, digestSz) != 0)) { + if ((innerAttribSz != digestSz) || + (XMEMCMP(attrib->value + idx, digestBuf, (word32)digestSz) != 0)) { WOLFSSL_MSG("Content digest does not match messageDigest attrib value"); #ifdef WOLFSSL_SMALL_STACK XFREE(digest, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER); @@ -4643,7 +4646,7 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf, XFREE(pkcs7->stream->tmpCert, pkcs7->heap, DYNAMIC_TYPE_PKCS7); pkcs7->stream->tmpCert = (byte*)XMALLOC(length, pkcs7->heap, DYNAMIC_TYPE_PKCS7); - if (pkcs7->stream->tmpCert == NULL) { + if ((pkiMsg2 == NULL) || (pkcs7->stream->tmpCert == NULL)) { ret = MEMORY_E; break; } @@ -8391,12 +8394,14 @@ static int wc_PKCS7_KariGetKeyEncryptionAlgorithmId(WC_PKCS7_KARI* kari, word32* keyAgreeOID, word32* keyWrapOID) { int length = 0; - word32 localIdx = *idx; + word32 localIdx; if (kari == NULL || pkiMsg == NULL || idx == NULL || keyAgreeOID == NULL || keyWrapOID == NULL) return BAD_FUNC_ARG; + localIdx = *idx; + /* remove KeyEncryptionAlgorithmIdentifier */ if (GetSequence(pkiMsg, &localIdx, &length, pkiMsgSz) < 0) return ASN_PARSE_E; diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index 8205d480b..e9f5b22ec 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -1467,7 +1467,7 @@ static int RsaUnPad_PSS(byte *pkcsBlock, unsigned int pkcsBlockLen, { int ret; byte* tmp; - int hLen, i, maskLen; + int hLen, i, maskLen, orig_bits = bits; #if defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_STATIC_MEMORY) byte tmp_buf[RSA_MAX_SIZE/8]; tmp = tmp_buf; @@ -1498,7 +1498,7 @@ static int RsaUnPad_PSS(byte *pkcsBlock, unsigned int pkcsBlockLen, saltLen = hLen; #ifdef WOLFSSL_SHA512 /* See FIPS 186-4 section 5.5 item (e). */ - if (bits == 1024 && hLen == WC_SHA512_DIGEST_SIZE) + if (orig_bits == 1024 && hLen == WC_SHA512_DIGEST_SIZE) saltLen = RSA_PSS_SALT_MAX_SZ; #endif }