mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 02:38:09 +09:00
known_hosts: Don't leak memory in ssh_write_knownhost error paths.
Found by Coverity.
This commit is contained in:
@@ -559,6 +559,9 @@ int ssh_write_knownhost(ssh_session session) {
|
|||||||
if(session->opts.port != 22) {
|
if(session->opts.port != 22) {
|
||||||
hostport = ssh_hostport(host, session->opts.port);
|
hostport = ssh_hostport(host, session->opts.port);
|
||||||
SAFE_FREE(host);
|
SAFE_FREE(host);
|
||||||
|
if (hostport == NULL) {
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
host = hostport;
|
host = hostport;
|
||||||
hostport = NULL;
|
hostport = NULL;
|
||||||
}
|
}
|
||||||
@@ -566,18 +569,21 @@ int ssh_write_knownhost(ssh_session session) {
|
|||||||
if (session->opts.knownhosts == NULL) {
|
if (session->opts.knownhosts == NULL) {
|
||||||
if (ssh_options_apply(session) < 0) {
|
if (ssh_options_apply(session) < 0) {
|
||||||
ssh_set_error(session, SSH_FATAL, "Can't find a known_hosts file");
|
ssh_set_error(session, SSH_FATAL, "Can't find a known_hosts file");
|
||||||
|
SAFE_FREE(host);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->current_crypto==NULL) {
|
if (session->current_crypto==NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL, "No current crypto context");
|
ssh_set_error(session, SSH_FATAL, "No current crypto context");
|
||||||
|
SAFE_FREE(host);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
pubkey_s = session->current_crypto->server_pubkey;
|
pubkey_s = session->current_crypto->server_pubkey;
|
||||||
if (pubkey_s == NULL){
|
if (pubkey_s == NULL){
|
||||||
ssh_set_error(session, SSH_FATAL, "No public key present");
|
ssh_set_error(session, SSH_FATAL, "No public key present");
|
||||||
|
SAFE_FREE(host);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,6 +591,7 @@ int ssh_write_knownhost(ssh_session session) {
|
|||||||
dir = ssh_dirname(session->opts.knownhosts);
|
dir = ssh_dirname(session->opts.knownhosts);
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL, "%s", strerror(errno));
|
ssh_set_error(session, SSH_FATAL, "%s", strerror(errno));
|
||||||
|
SAFE_FREE(host);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,6 +600,7 @@ int ssh_write_knownhost(ssh_session session) {
|
|||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
"Cannot create %s directory.", dir);
|
"Cannot create %s directory.", dir);
|
||||||
SAFE_FREE(dir);
|
SAFE_FREE(dir);
|
||||||
|
SAFE_FREE(host);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user