aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Malinen <jouni@codeaurora.org>2019-05-08 15:27:06 (GMT)
committerJouni Malinen <j@w1.fi>2019-05-08 15:27:06 (GMT)
commit7a9ddba6f524b49ae5c5f75000f504be572406a1 (patch)
tree7dfd41bae26a3206707c7ddbfa64556bcf39d5f7
parent7153540c39ca256739a6c66f90e8a9e552154062 (diff)
downloadhostap-7a9ddba6f524b49ae5c5f75000f504be572406a1.zip
hostap-7a9ddba6f524b49ae5c5f75000f504be572406a1.tar.gz
hostap-7a9ddba6f524b49ae5c5f75000f504be572406a1.tar.bz2
DPP: Fix a memory leak in key pair generation
ec_params needs to be free within dpp_gen_keypair() to avoid leaking the allocated memory. Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
-rw-r--r--src/common/dpp.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/common/dpp.c b/src/common/dpp.c
index 8094dfa..fa603a9 100644
--- a/src/common/dpp.c
+++ b/src/common/dpp.c
@@ -1135,7 +1135,7 @@ static void dpp_debug_print_key(const char *title, EVP_PKEY *key)
static EVP_PKEY * dpp_gen_keypair(const struct dpp_curve_params *curve)
{
EVP_PKEY_CTX *kctx = NULL;
- EC_KEY *ec_params;
+ EC_KEY *ec_params = NULL;
EVP_PKEY *params = NULL, *key = NULL;
int nid;
@@ -1166,19 +1166,18 @@ static EVP_PKEY * dpp_gen_keypair(const struct dpp_curve_params *curve)
EVP_PKEY_keygen_init(kctx) != 1 ||
EVP_PKEY_keygen(kctx, &key) != 1) {
wpa_printf(MSG_ERROR, "DPP: Failed to generate EC key");
+ key = NULL;
goto fail;
}
if (wpa_debug_show_keys)
dpp_debug_print_key("Own generated key", key);
+fail:
+ EC_KEY_free(ec_params);
EVP_PKEY_free(params);
EVP_PKEY_CTX_free(kctx);
return key;
-fail:
- EVP_PKEY_CTX_free(kctx);
- EVP_PKEY_free(params);
- return NULL;
}