From 223f25149b5b2afec7123cfd00ce33e797440943 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Tue, 7 Dec 2021 18:11:19 +0100 Subject: [PATCH] Return early on failed `key` init --- wolfcrypt/src/evp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index 389f92751..9ad03bc23 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -8182,6 +8182,13 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, return WOLFSSL_FAILURE; } + if (wc_ecc_init(&key) != 0) { + /* Return early so we don't have to remember if init succeeded + * or not. */ + mp_free(&a); + return WOLFSSL_FAILURE; + } + if (indent < 0) { indent = 0; } @@ -8189,8 +8196,6 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz, indent = EVP_PKEY_PRINT_INDENT_MAX; } - res = wc_ecc_init(&key) == 0; - if (res == WOLFSSL_SUCCESS) { res = wc_EccPublicKeyDecode(pkey, &inOutIdx, &key, pkeySz) == 0; }