Skip to content

Commit 6dab582

Browse files
committed
Various Coverity fixes
1 parent 1190d1b commit 6dab582

6 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/ssl_load.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,9 @@ static void ProcessBufferCertSetHave(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
15601560
}
15611561
#endif
15621562
#ifndef WC_STRICT_SIG
1563-
wolfssl_set_have_from_key_oid(ctx, ssl, cert->keyOID);
1563+
if ((ctx != NULL) || (ssl != NULL)) {
1564+
wolfssl_set_have_from_key_oid(ctx, ssl, cert->keyOID);
1565+
}
15641566
#else
15651567
/* Set whether ECC is available based on signature available. */
15661568
if (ssl != NULL) {

src/ssl_sess.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,12 +1711,12 @@ WOLFSSL_SESSION* ClientSessionToSession(const WOLFSSL_SESSION* session)
17111711
WOLFSSL_MSG("Client cache serverRow or serverIdx invalid");
17121712
error = -1;
17131713
}
1714-
/* Prevent memory access before clientSession->serverRow and
1715-
* clientSession->serverIdx are sanitized. */
1716-
XFENCE();
17171714
if (error == 0) {
17181715
/* Lock row */
17191716
sessRow = &SessionCache[clientSession->serverRow];
1717+
/* Prevent memory access before clientSession->serverRow and
1718+
* clientSession->serverIdx are sanitized. */
1719+
XFENCE();
17201720
error = SESSION_ROW_RD_LOCK(sessRow);
17211721
if (error != 0) {
17221722
WOLFSSL_MSG("Session cache row lock failure");
@@ -1729,6 +1729,8 @@ WOLFSSL_SESSION* ClientSessionToSession(const WOLFSSL_SESSION* session)
17291729
#else
17301730
cacheSession = &sessRow->Sessions[clientSession->serverIdx];
17311731
#endif
1732+
/* Prevent memory access */
1733+
XFENCE();
17321734
if (cacheSession && cacheSession->sessionIDSz == 0) {
17331735
cacheSession = NULL;
17341736
WOLFSSL_MSG("Session cache entry not set");

src/tls13.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12347,7 +12347,7 @@ int DoTls13HandShakeMsgType(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1234712347
{
1234812348
int ret = 0, tmp;
1234912349
word32 inIdx = *inOutIdx;
12350-
int alertType = invalid_alert;
12350+
int alertType;
1235112351
#if defined(HAVE_ECH)
1235212352
TLSX* echX = NULL;
1235312353
word32 echInOutIdx;

wolfcrypt/src/asn.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,8 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete,
14981498
int minDepth;
14991499
/* Integer had a zero prepended. */
15001500
int zeroPadded;
1501+
word32 tmpW32Val;
1502+
signed char tmpScharVal;
15011503

15021504
#ifdef WOLFSSL_DEBUG_ASN_TEMPLATE
15031505
WOLFSSL_ENTER("GetASN_Items");
@@ -1536,14 +1538,18 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete,
15361538
/* Check if first of numbered choice. */
15371539
if (choice == 0 && asn[i].optional > 1) {
15381540
choice = asn[i].optional;
1539-
if (choiceMet[choice - 2] == -1) {
1541+
tmpScharVal = choiceMet[choice - 2];
1542+
XFENCE(); /* Prevent memory access */
1543+
if (tmpScharVal == -1) {
15401544
/* Choice seen but not found a match yet. */
15411545
choiceMet[choice - 2] = 0;
15421546
}
15431547
}
15441548

15451549
/* Check for end of data or not a choice and tag not matching. */
1546-
if (idx == endIdx[depth] || (data[i].dataType != ASN_DATA_TYPE_CHOICE &&
1550+
tmpW32Val = endIdx[depth];
1551+
XFENCE(); /* Prevent memory access */
1552+
if (idx == tmpW32Val || (data[i].dataType != ASN_DATA_TYPE_CHOICE &&
15471553
(input[idx] & ~ASN_CONSTRUCTED) != asn[i].tag)) {
15481554
if (asn[i].optional) {
15491555
/* Skip over ASN.1 items underneath this optional item. */
@@ -1611,6 +1617,7 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete,
16111617

16121618
/* Store found tag in data. */
16131619
data[i].tag = input[idx];
1620+
XFENCE(); /* Prevent memory access */
16141621
if (data[i].dataType != ASN_DATA_TYPE_CHOICE) {
16151622
int constructed = (input[idx] & ASN_CONSTRUCTED) == ASN_CONSTRUCTED;
16161623
/* Check constructed match expected for non-choice ASN.1 item. */

wolfcrypt/src/rsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5243,7 +5243,7 @@ int wc_RsaPrivateKeyDecodeRaw(const byte* n, word32 nSz,
52435243
if (err == MP_OKAY) {
52445244
key->type = RSA_PRIVATE;
52455245
}
5246-
else {
5246+
else if (key != NULL) {
52475247
mp_clear(&key->n);
52485248
mp_clear(&key->e);
52495249
mp_clear(&key->d);

wolfcrypt/src/wc_port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ char* wc_strdup_ex(const char *src, int memType) {
11831183
word32 len = 0;
11841184

11851185
if (src) {
1186-
len = (word32)XSTRLEN(src);
1186+
len = (word32)XSTRLEN(src) + 1; /* Add one for null terminator */
11871187
ret = (char*)XMALLOC(len, NULL, memType);
11881188
if (ret != NULL) {
11891189
XMEMCPY(ret, src, len);

0 commit comments

Comments
 (0)