Skip to content

Commit 2537e08

Browse files
authored
Merge pull request #7890 from embhorn/zd18463
Various Coverity fixes
2 parents bf074d2 + 6dab582 commit 2537e08

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
@@ -1500,6 +1500,8 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete,
15001500
int minDepth;
15011501
/* Integer had a zero prepended. */
15021502
int zeroPadded;
1503+
word32 tmpW32Val;
1504+
signed char tmpScharVal;
15031505

15041506
#ifdef WOLFSSL_DEBUG_ASN_TEMPLATE
15051507
WOLFSSL_ENTER("GetASN_Items");
@@ -1538,14 +1540,18 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete,
15381540
/* Check if first of numbered choice. */
15391541
if (choice == 0 && asn[i].optional > 1) {
15401542
choice = asn[i].optional;
1541-
if (choiceMet[choice - 2] == -1) {
1543+
tmpScharVal = choiceMet[choice - 2];
1544+
XFENCE(); /* Prevent memory access */
1545+
if (tmpScharVal == -1) {
15421546
/* Choice seen but not found a match yet. */
15431547
choiceMet[choice - 2] = 0;
15441548
}
15451549
}
15461550

15471551
/* Check for end of data or not a choice and tag not matching. */
1548-
if (idx == endIdx[depth] || (data[i].dataType != ASN_DATA_TYPE_CHOICE &&
1552+
tmpW32Val = endIdx[depth];
1553+
XFENCE(); /* Prevent memory access */
1554+
if (idx == tmpW32Val || (data[i].dataType != ASN_DATA_TYPE_CHOICE &&
15491555
(input[idx] & ~ASN_CONSTRUCTED) != asn[i].tag)) {
15501556
if (asn[i].optional) {
15511557
/* Skip over ASN.1 items underneath this optional item. */
@@ -1613,6 +1619,7 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete,
16131619

16141620
/* Store found tag in data. */
16151621
data[i].tag = input[idx];
1622+
XFENCE(); /* Prevent memory access */
16161623
if (data[i].dataType != ASN_DATA_TYPE_CHOICE) {
16171624
int constructed = (input[idx] & ASN_CONSTRUCTED) == ASN_CONSTRUCTED;
16181625
/* 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)