Skip to content

Commit 8ac2a1a

Browse files
authored
Merge pull request #10418 from rlm2002/coverity
20260506 Coverity
2 parents 52847ed + f601946 commit 8ac2a1a

6 files changed

Lines changed: 33 additions & 14 deletions

File tree

src/tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14986,7 +14986,7 @@ static int TLSX_GetSize(TLSX* list, byte* semaphore, byte msgType,
1498614986
case TLSX_CERTIFICATE_AUTHORITIES: {
1498714987
word16 canSz = CAN_GET_SIZE(extension->data);
1498814988
/* 0 on non-empty list means 16-bit overflow. */
14989-
if (canSz == 0 && extension->data != NULL) {
14989+
if (canSz == 0) {
1499014990
ret = LENGTH_ERROR;
1499114991
break;
1499214992
}

src/tls13.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14536,8 +14536,7 @@ int wolfSSL_UseKeyShare(WOLFSSL* ssl, word16 group)
1453614536
if (WOLFSSL_NAMED_GROUP_IS_PQC(group) ||
1453714537
WOLFSSL_NAMED_GROUP_IS_PQC_HYBRID(group)) {
1453814538

14539-
if (ssl->ctx != NULL && ssl->ctx->method != NULL &&
14540-
!IsAtLeastTLSv1_3(ssl->version)) {
14539+
if (!IsAtLeastTLSv1_3(ssl->version)) {
1454114540
return BAD_FUNC_ARG;
1454214541
}
1454314542

tests/api/test_evp_digest.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,22 @@ int test_wolfSSL_EVP_DigestFinalXOF(void)
368368
ExpectIntEQ(sz, 16);
369369
ExpectIntEQ(EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
370370
#endif
371+
372+
/* NULL size pointer on the non-XOF Final must not crash;
373+
* defaults to 32 / 16 bytes for SHAKE256 / SHAKE128. */
374+
wolfSSL_EVP_MD_CTX_init(&mdCtx);
375+
ExpectIntEQ(EVP_DigestInit(&mdCtx, EVP_shake256()), WOLFSSL_SUCCESS);
376+
ExpectIntEQ(EVP_DigestUpdate(&mdCtx, data, 1), WOLFSSL_SUCCESS);
377+
ExpectIntEQ(EVP_DigestFinal(&mdCtx, shake, NULL), WOLFSSL_SUCCESS);
378+
ExpectIntEQ(EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
379+
380+
#if defined(WOLFSSL_SHAKE128)
381+
wolfSSL_EVP_MD_CTX_init(&mdCtx);
382+
ExpectIntEQ(EVP_DigestInit(&mdCtx, EVP_shake128()), WOLFSSL_SUCCESS);
383+
ExpectIntEQ(EVP_DigestUpdate(&mdCtx, data, 1), WOLFSSL_SUCCESS);
384+
ExpectIntEQ(EVP_DigestFinal(&mdCtx, shake, NULL), WOLFSSL_SUCCESS);
385+
ExpectIntEQ(EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
386+
#endif
371387
#endif
372388
return EXPECT_RESULT();
373389
}

wolfcrypt/src/asn.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,6 @@ int SizeASN_Items(const ASNItem* asn, ASNSetData *data, int count,
868868
return ASN_PARSE_E;
869869
}
870870
length += mp_leading_bit(data[i].data.mp) ? 1 : 0;
871-
if (length < 0) {
872-
return ASN_PARSE_E;
873-
}
874871
len = (word32)SizeASNHeader((word32)length) + (word32)length;
875872
/* Check for overflow: header + length must not wrap word32. */
876873
if (len < (word32)length) {

wolfcrypt/src/evp.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11317,6 +11317,10 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
1131711317
unsigned int* s)
1131811318
{
1131911319
enum wc_HashType macType;
11320+
#if defined(WOLFSSL_SHA3) && (defined(WOLFSSL_SHAKE128) || \
11321+
defined(WOLFSSL_SHAKE256))
11322+
unsigned int defaultSz = 0;
11323+
#endif
1132011324

1132111325
WOLFSSL_ENTER("wolfSSL_EVP_DigestFinal");
1132211326

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

1134611350
case WC_HASH_TYPE_SHAKE128:
1134711351
#if defined(WOLFSSL_SHA3) && defined(WOLFSSL_SHAKE128)
11348-
if (s != NULL)
11349-
*s = 16; /* if mixing up XOF with plain digest 128 bit is
11350-
* default for SHAKE128 */
11352+
if (s == NULL)
11353+
s = &defaultSz;
11354+
*s = 16; /* if mixing up XOF with plain digest 128 bit is
11355+
* default for SHAKE128 */
11356+
1135111357
#else
1135211358
return WOLFSSL_FAILURE;
1135311359
#endif
1135411360
break;
1135511361
case WC_HASH_TYPE_SHAKE256:
1135611362
#if defined(WOLFSSL_SHA3) && defined(WOLFSSL_SHAKE256)
11357-
if (s != NULL)
11358-
*s = 32; /* if mixing up XOF with plain digest 256 bit is
11359-
* default for SHAKE256 */
11363+
if (s == NULL)
11364+
s = &defaultSz;
11365+
*s = 32; /* if mixing up XOF with plain digest 256 bit is
11366+
* default for SHAKE256 */
1136011367
#else
1136111368
return WOLFSSL_FAILURE;
1136211369
#endif

wolfcrypt/src/wc_encrypt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ int wc_CryptKey(const char* password, int passwordSz, const byte* salt,
468468
byte unicodePasswd[MAX_UNICODE_SZ];
469469

470470
if (passwordSz < 0 ||
471-
passwordSz >= (int)sizeof(unicodePasswd) ||
472-
(passwordSz * 2 + 2) > (int)sizeof(unicodePasswd)) {
471+
passwordSz >= MAX_UNICODE_SZ ||
472+
(passwordSz * 2 + 2) > MAX_UNICODE_SZ) {
473473
ret = UNICODE_SIZE_E;
474474
break;
475475
}

0 commit comments

Comments
 (0)