Skip to content
Open

Coverity #10418

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -14986,7 +14986,7 @@ static int TLSX_GetSize(TLSX* list, byte* semaphore, byte msgType,
case TLSX_CERTIFICATE_AUTHORITIES: {
word16 canSz = CAN_GET_SIZE(extension->data);
/* 0 on non-empty list means 16-bit overflow. */
if (canSz == 0 && extension->data != NULL) {
if (canSz == 0) {
ret = LENGTH_ERROR;
break;
}
Expand Down
3 changes: 1 addition & 2 deletions src/tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -14532,8 +14532,7 @@ int wolfSSL_UseKeyShare(WOLFSSL* ssl, word16 group)
if (WOLFSSL_NAMED_GROUP_IS_PQC(group) ||
WOLFSSL_NAMED_GROUP_IS_PQC_HYBRID(group)) {

if (ssl->ctx != NULL && ssl->ctx->method != NULL &&
!IsAtLeastTLSv1_3(ssl->version)) {
if (!IsAtLeastTLSv1_3(ssl->version)) {
return BAD_FUNC_ARG;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/api/test_evp_digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,22 @@ int test_wolfSSL_EVP_DigestFinalXOF(void)
ExpectIntEQ(sz, 16);
ExpectIntEQ(EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
#endif

/* NULL size pointer on the non-XOF Final must not crash;
* defaults to 32 / 16 bytes for SHAKE256 / SHAKE128. */
wolfSSL_EVP_MD_CTX_init(&mdCtx);
ExpectIntEQ(EVP_DigestInit(&mdCtx, EVP_shake256()), WOLFSSL_SUCCESS);
ExpectIntEQ(EVP_DigestUpdate(&mdCtx, data, 1), WOLFSSL_SUCCESS);
ExpectIntEQ(EVP_DigestFinal(&mdCtx, shake, NULL), WOLFSSL_SUCCESS);
ExpectIntEQ(EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);

#if defined(WOLFSSL_SHAKE128)
wolfSSL_EVP_MD_CTX_init(&mdCtx);
ExpectIntEQ(EVP_DigestInit(&mdCtx, EVP_shake128()), WOLFSSL_SUCCESS);
ExpectIntEQ(EVP_DigestUpdate(&mdCtx, data, 1), WOLFSSL_SUCCESS);
ExpectIntEQ(EVP_DigestFinal(&mdCtx, shake, NULL), WOLFSSL_SUCCESS);
ExpectIntEQ(EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
#endif
#endif
return EXPECT_RESULT();
}
Expand Down
3 changes: 0 additions & 3 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,6 @@ int SizeASN_Items(const ASNItem* asn, ASNSetData *data, int count,
return ASN_PARSE_E;
}
length += mp_leading_bit(data[i].data.mp) ? 1 : 0;
if (length < 0) {
return ASN_PARSE_E;
}
len = (word32)SizeASNHeader((word32)length) + (word32)length;
/* Check for overflow: header + length must not wrap word32. */
if (len < (word32)length) {
Expand Down
19 changes: 13 additions & 6 deletions wolfcrypt/src/evp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11317,6 +11317,10 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
unsigned int* s)
{
enum wc_HashType macType;
#if defined(WOLFSSL_SHA3) && (defined(WOLFSSL_SHAKE128) || \
defined(WOLFSSL_SHAKE256))
unsigned int defaultSz = 0;
#endif

WOLFSSL_ENTER("wolfSSL_EVP_DigestFinal");

Expand Down Expand Up @@ -11345,18 +11349,21 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)

case WC_HASH_TYPE_SHAKE128:
#if defined(WOLFSSL_SHA3) && defined(WOLFSSL_SHAKE128)
if (s != NULL)
*s = 16; /* if mixing up XOF with plain digest 128 bit is
* default for SHAKE128 */
if (s == NULL)
s = &defaultSz;
*s = 16; /* if mixing up XOF with plain digest 128 bit is
* default for SHAKE128 */

#else
return WOLFSSL_FAILURE;
#endif
break;
case WC_HASH_TYPE_SHAKE256:
#if defined(WOLFSSL_SHA3) && defined(WOLFSSL_SHAKE256)
if (s != NULL)
*s = 32; /* if mixing up XOF with plain digest 256 bit is
* default for SHAKE256 */
if (s == NULL)
s = &defaultSz;
*s = 32; /* if mixing up XOF with plain digest 256 bit is
* default for SHAKE256 */
#else
return WOLFSSL_FAILURE;
#endif
Expand Down
4 changes: 2 additions & 2 deletions wolfcrypt/src/wc_encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ int wc_CryptKey(const char* password, int passwordSz, const byte* salt,
byte unicodePasswd[MAX_UNICODE_SZ];

if (passwordSz < 0 ||
passwordSz >= (int)sizeof(unicodePasswd) ||
(passwordSz * 2 + 2) > (int)sizeof(unicodePasswd)) {
passwordSz >= MAX_UNICODE_SZ ||
(passwordSz * 2 + 2) > MAX_UNICODE_SZ) {
ret = UNICODE_SIZE_E;
break;
}
Expand Down
Loading