Skip to content

Commit b168bfa

Browse files
julek-wolfssldgarske
authored andcommitted
Check wc_ecc_init_ex return value in wc_GetKeyOID
F-749
1 parent 265fbdb commit b168bfa

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9510,22 +9510,23 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
95109510
return MEMORY_E;
95119511

95129512
tmpIdx = 0;
9513-
wc_ecc_init_ex(ecc, heap, INVALID_DEVID);
9514-
if (wc_EccPrivateKeyDecode(key, &tmpIdx, ecc, keySz) == 0) {
9515-
*algoID = ECDSAk;
9516-
9517-
/* now find oid */
9518-
if (wc_ecc_get_oid(ecc->dp->oidSum, curveOID, oidSz) < 0) {
9519-
WOLFSSL_MSG("Error getting ECC curve OID");
9520-
wc_ecc_free(ecc);
9521-
XFREE(ecc, heap, DYNAMIC_TYPE_TMP_BUFFER);
9522-
return BAD_FUNC_ARG;
9513+
if (wc_ecc_init_ex(ecc, heap, INVALID_DEVID) == 0) {
9514+
if (wc_EccPrivateKeyDecode(key, &tmpIdx, ecc, keySz) == 0) {
9515+
*algoID = ECDSAk;
9516+
9517+
/* now find oid */
9518+
if (wc_ecc_get_oid(ecc->dp->oidSum, curveOID, oidSz) < 0) {
9519+
WOLFSSL_MSG("Error getting ECC curve OID");
9520+
wc_ecc_free(ecc);
9521+
XFREE(ecc, heap, DYNAMIC_TYPE_TMP_BUFFER);
9522+
return BAD_FUNC_ARG;
9523+
}
95239524
}
9525+
else {
9526+
WOLFSSL_MSG("Not ECC DER key either");
9527+
}
9528+
wc_ecc_free(ecc);
95249529
}
9525-
else {
9526-
WOLFSSL_MSG("Not ECC DER key either");
9527-
}
9528-
wc_ecc_free(ecc);
95299530
XFREE(ecc, heap, DYNAMIC_TYPE_TMP_BUFFER);
95309531
}
95319532
#endif /* HAVE_ECC && !NO_ASN_CRYPT */

0 commit comments

Comments
 (0)