Skip to content

Commit 02bdde0

Browse files
committed
asn: fix coverity null deref warnings.
1 parent a05a3ed commit 02bdde0

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12380,7 +12380,9 @@ int wc_DsaPublicKeyDecode(const byte* input, word32* inOutIdx, DsaKey* key,
1238012380
ret = BAD_FUNC_ARG;
1238112381
}
1238212382

12383-
ALLOC_ASNGETDATA(dataASN, dsaPubKeyASN_Length, ret, key->heap);
12383+
if (ret == 0) {
12384+
ALLOC_ASNGETDATA(dataASN, dsaPubKeyASN_Length, ret, key->heap);
12385+
}
1238412386

1238512387
if (ret == 0) {
1238612388
int i;
@@ -13010,7 +13012,7 @@ static int DsaKeyIntsToDer(DsaKey* key, byte* output, word32* inLen,
1301013012
ret = (int)sz;
1301113013
}
1301213014

13013-
FREE_ASNSETDATA(dataASN, key->heap);
13015+
FREE_ASNSETDATA(dataASN, key != NULL ? key->heap : NULL);
1301413016
return ret;
1301513017
#endif /* WOLFSSL_ASN_TEMPLATE */
1301613018
}
@@ -37127,7 +37129,9 @@ int wc_EccPrivateKeyDecode(const byte* input, word32* inOutIdx, ecc_key* key,
3712737129
}
3712837130
#endif
3712937131

37130-
CALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
37132+
if (ret == 0) {
37133+
CALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
37134+
}
3713137135

3713237136
if (ret == 0) {
3713337137
/* Get the version and set the expected OID type. */
@@ -37538,7 +37542,9 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
3753837542
ret = BAD_FUNC_ARG;
3753937543
}
3754037544

37541-
ALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
37545+
if (ret == 0) {
37546+
ALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
37547+
}
3754237548

3754337549
if (ret == 0) {
3754437550
/* Clear dynamic data for ECC public key. */
@@ -37901,7 +37907,7 @@ int wc_BuildEccKeyDer(ecc_key* key, byte* output, word32 *inLen,
3790137907
ret = (int)sz;
3790237908
}
3790337909

37904-
FREE_ASNSETDATA(dataASN, key->heap);
37910+
FREE_ASNSETDATA(dataASN, key != NULL ? key->heap : NULL);
3790537911
return ret;
3790637912
#endif
3790737913
}

0 commit comments

Comments
 (0)