mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-03-07 00:54:02 +01:00
fixes/workarounds for -Wnull-dereferences, some true positive, some false
positive: * src/pk.c:wolfSSL_RSA_meth_new() * tests/api.c:test_wolfSSL_PKCS7_certs() * tests/api.c:test_wolfSSL_X509V3_EXT_get() * wolfcrypt/src/asn.c:EncodeName() * wolfcrypt/src/pkcs12.c:wc_i2d_PKCS12() * wolfcrypt/src/port/af_alg/afalg_aes.c
This commit is contained in:
@@ -29922,6 +29922,9 @@ static int EncodeName(EncodedName* name, const char* nameStr,
|
||||
name->used = 0;
|
||||
return 0;
|
||||
}
|
||||
nameSz = (word32)cname->custom.valSz;
|
||||
oid = cname->custom.oid;
|
||||
oidSz = (word32)cname->custom.oidSz;
|
||||
}
|
||||
#else
|
||||
(void)cname;
|
||||
@@ -29961,9 +29964,9 @@ static int EncodeName(EncodedName* name, const char* nameStr,
|
||||
break;
|
||||
#ifdef WOLFSSL_CUSTOM_OID
|
||||
case ASN_CUSTOM_NAME:
|
||||
nameSz = (word32)cname->custom.valSz;
|
||||
oid = cname->custom.oid;
|
||||
oidSz = (word32)cname->custom.oidSz;
|
||||
/* oid setup is above (mitigating false positive
|
||||
* -Wnull-dereference).
|
||||
*/
|
||||
break;
|
||||
#endif
|
||||
#ifdef WOLFSSL_CERT_REQ
|
||||
|
||||
@@ -977,8 +977,10 @@ int wc_i2d_PKCS12(WC_PKCS12* pkcs12, byte** der, int* derSz)
|
||||
totalSz += seqSz;
|
||||
|
||||
/* check if getting length only */
|
||||
if (der == NULL && derSz != NULL) {
|
||||
*derSz = (int)totalSz;
|
||||
if (der == NULL) {
|
||||
/* repeat nullness check locally to mollify -Wnull-dereference. */
|
||||
if (derSz != NULL)
|
||||
*derSz = (int)totalSz;
|
||||
XFREE(sdBuf, pkcs12->heap, DYNAMIC_TYPE_PKCS);
|
||||
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
|
||||
}
|
||||
|
||||
@@ -186,6 +186,10 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
|
||||
if ((sz / WC_AES_BLOCK_SIZE) > 0) {
|
||||
/* update IV */
|
||||
cmsg = CMSG_FIRSTHDR(&(aes->msg));
|
||||
if (cmsg == NULL) {
|
||||
WOLFSSL_MSG("CMSG_FIRSTHDR() in wc_AesCbcEncrypt() returned NULL unexpectedly.");
|
||||
return SYSLIB_FAILED_E;
|
||||
}
|
||||
ret = wc_Afalg_SetIv(CMSG_NXTHDR(&(aes->msg), cmsg),
|
||||
(byte*)(aes->reg), AES_IV_SIZE);
|
||||
if (ret < 0) {
|
||||
@@ -245,6 +249,10 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
|
||||
if ((sz / WC_AES_BLOCK_SIZE) > 0) {
|
||||
/* update IV */
|
||||
cmsg = CMSG_FIRSTHDR(&(aes->msg));
|
||||
if (cmsg == NULL) {
|
||||
WOLFSSL_MSG("CMSG_FIRSTHDR() in wc_AesCbcDecrypt() returned NULL unexpectedly.");
|
||||
return SYSLIB_FAILED_E;
|
||||
}
|
||||
ret = wc_Afalg_SetIv(CMSG_NXTHDR(&(aes->msg), cmsg),
|
||||
(byte*)(aes->reg), AES_IV_SIZE);
|
||||
if (ret != 0) {
|
||||
@@ -397,6 +405,10 @@ int wc_AesSetKeyDirect(Aes* aes, const byte* userKey, word32 keylen,
|
||||
|
||||
/* update IV */
|
||||
cmsg = CMSG_FIRSTHDR(&(aes->msg));
|
||||
if (cmsg == NULL) {
|
||||
WOLFSSL_MSG("CMSG_FIRSTHDR() in wc_AesCtrEncrypt() returned NULL unexpectedly.");
|
||||
return SYSLIB_FAILED_E;
|
||||
}
|
||||
ret = wc_Afalg_SetIv(CMSG_NXTHDR(&(aes->msg), cmsg),
|
||||
(byte*)(aes->reg), AES_IV_SIZE);
|
||||
if (ret < 0) {
|
||||
@@ -613,7 +625,15 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
||||
|
||||
msg = &(aes->msg);
|
||||
cmsg = CMSG_FIRSTHDR(msg);
|
||||
if (cmsg == NULL) {
|
||||
WOLFSSL_MSG("CMSG_FIRSTHDR() in wc_AesGcmEncrypt() returned NULL unexpectedly.");
|
||||
return SYSLIB_FAILED_E;
|
||||
}
|
||||
cmsg = CMSG_NXTHDR(msg, cmsg);
|
||||
if (cmsg == NULL) {
|
||||
WOLFSSL_MSG("CMSG_NEXTHDR() in wc_AesGcmEncrypt() returned NULL unexpectedly.");
|
||||
return SYSLIB_FAILED_E;
|
||||
}
|
||||
|
||||
/* set IV and AAD size */
|
||||
ret = wc_Afalg_SetIv(cmsg, (byte*)iv, ivSz);
|
||||
|
||||
Reference in New Issue
Block a user