From 5d712ac5d84665014ef6fae830b9eba0b06a037f Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Wed, 7 Feb 2024 09:02:20 +0100 Subject: [PATCH] session client BUGFIX use-after-free --- src/session_client_ssh.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/session_client_ssh.c b/src/session_client_ssh.c index 937092d4..4b68fe31 100644 --- a/src/session_client_ssh.c +++ b/src/session_client_ssh.c @@ -1523,16 +1523,18 @@ _nc_connect_libssh(ssh_session ssh_session, struct ly_ctx *ctx, struct nc_keepal free(host); goto fail; } - free(host); /* create and connect socket */ sock = nc_sock_connect(host, port, -1, ka, NULL, &ip_host); if (sock == -1) { ERR(NULL, "Unable to connect to %s:%u (%s).", host, port, strerror(errno)); + free(host); goto fail; } ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_FD, &sock); ssh_set_blocking(session->ti.libssh.session, 0); + + free(host); host = ip_host; }