aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2020-03-02 11:36:18 +0100
committerAndreas Schneider <asn@cryptomilk.org>2020-03-29 09:59:52 +0200
commit4c83d19c4865eb814689067152f5835323a8709c (patch)
tree9ad8f1d72a128f2afb9572ab4916a94fcd247024
parent673bf1ff09a623592386a7ee7bb2b02c8d344153 (diff)
downloadlibssh-4c83d19c4865eb814689067152f5835323a8709c.tar.gz
libssh-4c83d19c4865eb814689067152f5835323a8709c.tar.xz
libssh-4c83d19c4865eb814689067152f5835323a8709c.zip
auth: Fix memory leak in ssh_userauth_publickey_auto()
When a key is rejected, free the allocated memory before returning. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> (cherry picked from commit 6bd2b93f43dacceaf060d1aeb89749eba7df2cbb)
-rw-r--r--src/auth.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/auth.c b/src/auth.c
index f2eeee0b..3a5f0efb 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -1116,7 +1116,9 @@ int ssh_userauth_publickey_auto(ssh_session session,
"Public key authentication error for %s",
privkey_file);
ssh_key_free(state->privkey);
+ state->privkey = NULL;
ssh_key_free(state->pubkey);
+ state->pubkey = NULL;
SAFE_FREE(session->auth.auto_state);
return rc;
} else if (rc == SSH_AUTH_AGAIN) {
@@ -1182,6 +1184,9 @@ int ssh_userauth_publickey_auto(ssh_session session,
return rc;
}
+ ssh_key_free(state->privkey);
+ ssh_key_free(state->pubkey);
+
SSH_LOG(SSH_LOG_WARN,
"The server accepted the public key but refused the signature");
state->it = state->it->next;