From a50d7debfdf48d1e2a438e052b22cb787b91ed34 Mon Sep 17 00:00:00 2001 From: Will Cosgrove Date: Tue, 23 Jul 2024 10:32:13 -0700 Subject: [PATCH] Always init mbedtls_pk_context (#1430) In the failure case, mbedtls_pk_context could be free'd without first being initialized. --- src/mbedtls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mbedtls.c b/src/mbedtls.c index 90a5fe17..a66e36c5 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -1297,12 +1297,12 @@ _libssh2_mbedtls_ecdsa_new_private(libssh2_ecdsa_ctx **ctx, unsigned char *data = NULL; size_t data_len = 0; + mbedtls_pk_init(&pkey); + /* FIXME: Reimplement this functionality via a public API. */ if(mbedtls_pk_load_file(filename, &data, &data_len)) goto cleanup; - mbedtls_pk_init(&pkey); - if(_libssh2_mbedtls_parse_eckey(ctx, &pkey, session, data, data_len, pwd) == 0) goto cleanup;