mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-10-24 03:48:55 +03:00
config: Fix possible memory leak of jump_host
Thanks coverity CID 1687968 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Pavol Žáčik <pzacik@redhat.com> Merge-Request: <https://gitlab.com/libssh/libssh-mirror/-/merge_requests/896>
This commit is contained in:
@@ -92,6 +92,8 @@ struct ssh_jump_info_struct {
|
||||
int port;
|
||||
};
|
||||
|
||||
void ssh_jump_info_free(struct ssh_jump_info_struct *jump);
|
||||
|
||||
struct ssh_timestamp {
|
||||
long seconds;
|
||||
long useconds;
|
||||
|
||||
@@ -656,7 +656,6 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing)
|
||||
false);
|
||||
if (rv != SSH_OK) {
|
||||
ssh_set_error_invalid(session);
|
||||
SAFE_FREE(jump_host);
|
||||
goto out;
|
||||
}
|
||||
/* Leave the port at 0 when it is not given, so that the jump
|
||||
@@ -671,7 +670,6 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing)
|
||||
session->opts.proxy_jumps = ssh_list_new();
|
||||
if (session->opts.proxy_jumps == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
SAFE_FREE(jump_host);
|
||||
rv = SSH_ERROR;
|
||||
goto out;
|
||||
}
|
||||
@@ -681,9 +679,10 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing)
|
||||
rv = ssh_list_prepend(session->opts.proxy_jumps, jump_host);
|
||||
if (rv != SSH_OK) {
|
||||
ssh_set_error_oom(session);
|
||||
SAFE_FREE(jump_host);
|
||||
goto out;
|
||||
}
|
||||
/* moved ownership to the ssh_list */
|
||||
jump_host = NULL;
|
||||
} else if (parse_entry) {
|
||||
/* We actually care only about the first item */
|
||||
rv = ssh_config_parse_uri(cp,
|
||||
@@ -752,6 +751,7 @@ out:
|
||||
if (rv != SSH_OK) {
|
||||
ssh_proxyjumps_free(session->opts.proxy_jumps);
|
||||
}
|
||||
ssh_jump_info_free(jump_host);
|
||||
SAFE_FREE(username);
|
||||
SAFE_FREE(hostname);
|
||||
SAFE_FREE(port);
|
||||
@@ -1814,7 +1814,7 @@ static int ssh_config_parse_line_internal(ssh_session session,
|
||||
CHECK_COND_OR_FAIL(1, "Invalid data limit");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
val = (double)ll;
|
||||
if (*endp == '.') {
|
||||
endp++;
|
||||
|
||||
19
src/misc.c
19
src/misc.c
@@ -2646,6 +2646,21 @@ int ssh_check_username_syntax(const char *username)
|
||||
return SSH_OK;
|
||||
}
|
||||
|
||||
/* @brief Free the ssh_jump_info_struct and its members.
|
||||
*
|
||||
* @param[in] jump Proxy jump info structure to free (may be NULL)
|
||||
*/
|
||||
void ssh_jump_info_free(struct ssh_jump_info_struct *jump)
|
||||
{
|
||||
if (jump == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SAFE_FREE(jump->hostname);
|
||||
SAFE_FREE(jump->username);
|
||||
SAFE_FREE(jump);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Free proxy jump list
|
||||
*
|
||||
@@ -2664,9 +2679,7 @@ ssh_proxyjumps_free(struct ssh_list *proxy_jump_list)
|
||||
jump != NULL;
|
||||
jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
|
||||
proxy_jump_list)) {
|
||||
SAFE_FREE(jump->hostname);
|
||||
SAFE_FREE(jump->username);
|
||||
SAFE_FREE(jump);
|
||||
ssh_jump_info_free(jump);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user