Skip to content

Commit 0792c67

Browse files
authored
Merge pull request #9960 from philljj/fix_coverity
asn: fix coverity null deref warnings.
2 parents 00cd1a7 + 02bdde0 commit 0792c67

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;
@@ -13011,7 +13013,7 @@ static int DsaKeyIntsToDer(DsaKey* key, byte* output, word32* inLen,
1301113013
ret = (int)sz;
1301213014
}
1301313015

13014-
FREE_ASNSETDATA(dataASN, key->heap);
13016+
FREE_ASNSETDATA(dataASN, key != NULL ? key->heap : NULL);
1301513017
return ret;
1301613018
#endif /* WOLFSSL_ASN_TEMPLATE */
1301713019
}
@@ -37132,7 +37134,9 @@ int wc_EccPrivateKeyDecode(const byte* input, word32* inOutIdx, ecc_key* key,
3713237134
}
3713337135
#endif
3713437136

37135-
CALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
37137+
if (ret == 0) {
37138+
CALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
37139+
}
3713637140

3713737141
if (ret == 0) {
3713837142
/* Get the version and set the expected OID type. */
@@ -37543,7 +37547,9 @@ int wc_EccPublicKeyDecode(const byte* input, word32* inOutIdx,
3754337547
ret = BAD_FUNC_ARG;
3754437548
}
3754537549

37546-
ALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
37550+
if (ret == 0) {
37551+
ALLOC_ASNGETDATA(dataASN, eccKeyASN_Length, ret, key->heap);
37552+
}
3754737553

3754837554
if (ret == 0) {
3754937555
/* Clear dynamic data for ECC public key. */
@@ -37906,7 +37912,7 @@ int wc_BuildEccKeyDer(ecc_key* key, byte* output, word32 *inLen,
3790637912
ret = (int)sz;
3790737913
}
3790837914

37909-
FREE_ASNSETDATA(dataASN, key->heap);
37915+
FREE_ASNSETDATA(dataASN, key != NULL ? key->heap : NULL);
3791037916
return ret;
3791137917
#endif
3791237918
}

0 commit comments

Comments
 (0)