Skip to content

Commit

Permalink
Merge pull request wolfSSL#8085 from philljj/fix_coverity
Browse files Browse the repository at this point in the history
Fix coverity errors
  • Loading branch information
douzzer authored Oct 16, 2024
2 parents cc421dd + 554ebc2 commit 8803f3d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ssl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static int wolfssl_i2d_asn1_items(const void* obj, byte* buf,
len = 0;
break;
}
if (buf != NULL && !mem->ex && mem->tag >= 0) {
if (buf != NULL && tmp != NULL && !mem->ex && mem->tag >= 0) {
/* Encode the implicit tag */
byte imp[ASN_TAG_SZ + MAX_LENGTH_SZ];
SetImplicit(tmp[0], mem->tag, 0, imp, 0);
Expand Down
8 changes: 6 additions & 2 deletions wolfcrypt/src/pkcs7.c
Original file line number Diff line number Diff line change
Expand Up @@ -13698,6 +13698,7 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* in,
/* free memory, zero out keys */
ForceZero(encryptedContent, (word32)encryptedContentSz);
XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
encryptedContent = NULL;
ForceZero(decryptedKey, MAX_ENCRYPTED_KEY_SZ);
#ifdef WOLFSSL_SMALL_STACK
XFREE(decryptedKey, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
Expand Down Expand Up @@ -13726,8 +13727,11 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* in,
}
#else
if (ret < 0) {
ForceZero(encryptedContent, (word32)encryptedContentSz);
XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
if (encryptedContent != NULL) {
ForceZero(encryptedContent, (word32)encryptedContentSz);
XFREE(encryptedContent, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
encryptedContent = NULL;
}
ForceZero(decryptedKey, MAX_ENCRYPTED_KEY_SZ);
}
#endif
Expand Down
14 changes: 11 additions & 3 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -56315,16 +56315,24 @@ static wc_test_ret_t mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC
/* a = 2^(bits*2) - 1 */
mp_zero(a);
mp_set_bit(a, bits[i] * 2);
mp_sub_d(a, 1, a);
ret = mp_sub_d(a, 1, a);
if (ret != MP_OKAY)
return WC_TEST_RET_ENC_EC(ret);

/* m = 2^(bits) - 1 */
mp_zero(m);
mp_set_bit(m, bits[i]);
mp_sub_d(m, 1, m);
ret = mp_sub_d(m, 1, m);
if (ret != MP_OKAY)
return WC_TEST_RET_ENC_EC(ret);

mp = 1;
/* result = r = 2^(bits) - 1 */
mp_zero(r);
mp_set_bit(r, bits[i]);
mp_sub_d(r, 1, r);
ret = mp_sub_d(r, 1, r);
if (ret != MP_OKAY)
return WC_TEST_RET_ENC_EC(ret);

ret = mp_montgomery_reduce(a, m, mp);
if (ret != MP_OKAY)
Expand Down

0 comments on commit 8803f3d

Please sign in to comment.