From 7a9eb02e472e809ace37a5d0e99cebde5734a894 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 4 Feb 2019 20:12:50 +0000 Subject: [PATCH] sshecc.c: reliably initialise ek->privateKey. If something goes wrong part way through one of the new-key functions, we immediately call the corresponding freekey function before returning failure. That will test ek->privateKey for NULL, and if it's not NULL, try to free it - so we should be sure it _is_ NULL if we haven't put a private key in it. --- sshecc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sshecc.c b/sshecc.c index 15775ad4..54697320 100644 --- a/sshecc.c +++ b/sshecc.c @@ -567,6 +567,7 @@ static ssh_key *ecdsa_new_pub(const ssh_keyalg *alg, ptrlen data) struct ecdsa_key *ek = snew(struct ecdsa_key); ek->sshk.vt = alg; ek->curve = curve; + ek->privateKey = NULL; ek->publicKey = get_wpoint(src, curve); if (!ek->publicKey) { @@ -574,8 +575,6 @@ static ssh_key *ecdsa_new_pub(const ssh_keyalg *alg, ptrlen data) return NULL; } - ek->privateKey = NULL; - return &ek->sshk; } @@ -742,6 +741,7 @@ static ssh_key *eddsa_new_priv_openssh( struct eddsa_key *ek = snew(struct eddsa_key); ek->sshk.vt = alg; ek->curve = curve; + ek->privateKey = NULL; ek->publicKey = eddsa_decode(pubkey_pl, curve); if (!ek->publicKey) { @@ -793,6 +793,7 @@ static ssh_key *ecdsa_new_priv_openssh( struct eddsa_key *ek = snew(struct eddsa_key); ek->sshk.vt = alg; ek->curve = curve; + ek->privateKey = NULL; ek->publicKey = get_epoint(src, curve); if (!ek->publicKey) {