aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2012-10-08 20:52:30 +0200
committerAndreas Schneider <asn@cryptomilk.org>2012-10-12 08:07:01 +0200
commit02953019283fca8069bb7a3a4a11c7bedd2941fc (patch)
tree8ae46a12c9dd8645142b11714f05a5129a40db02
parenta6e7d1f255bd1ac5df3366c985487fc1e13d33a3 (diff)
downloadlibssh-02953019283fca8069bb7a3a4a11c7bedd2941fc.tar.gz
libssh-02953019283fca8069bb7a3a4a11c7bedd2941fc.tar.xz
libssh-02953019283fca8069bb7a3a4a11c7bedd2941fc.zip
known_hosts: Don't leak memory in ssh_write_knownhost error paths.
Found by Coverity.
-rw-r--r--src/known_hosts.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/known_hosts.c b/src/known_hosts.c
index c217aed1..2d281e72 100644
--- a/src/known_hosts.c
+++ b/src/known_hosts.c
@@ -559,6 +559,9 @@ int ssh_write_knownhost(ssh_session session) {
if(session->opts.port != 22) {
hostport = ssh_hostport(host, session->opts.port);
SAFE_FREE(host);
+ if (hostport == NULL) {
+ return SSH_ERROR;
+ }
host = hostport;
hostport = NULL;
}
@@ -566,18 +569,21 @@ int ssh_write_knownhost(ssh_session session) {
if (session->opts.knownhosts == NULL) {
if (ssh_options_apply(session) < 0) {
ssh_set_error(session, SSH_FATAL, "Can't find a known_hosts file");
+ SAFE_FREE(host);
return SSH_ERROR;
}
}
if (session->current_crypto==NULL) {
ssh_set_error(session, SSH_FATAL, "No current crypto context");
+ SAFE_FREE(host);
return SSH_ERROR;
}
pubkey_s = session->current_crypto->server_pubkey;
if (pubkey_s == NULL){
ssh_set_error(session, SSH_FATAL, "No public key present");
+ SAFE_FREE(host);
return SSH_ERROR;
}
@@ -585,6 +591,7 @@ int ssh_write_knownhost(ssh_session session) {
dir = ssh_dirname(session->opts.knownhosts);
if (dir == NULL) {
ssh_set_error(session, SSH_FATAL, "%s", strerror(errno));
+ SAFE_FREE(host);
return SSH_ERROR;
}
@@ -593,6 +600,7 @@ int ssh_write_knownhost(ssh_session session) {
ssh_set_error(session, SSH_FATAL,
"Cannot create %s directory.", dir);
SAFE_FREE(dir);
+ SAFE_FREE(host);
return SSH_ERROR;
}
}