From 42044e42799402898c00ace8ca770c94f6799843 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Fri, 6 Apr 2018 06:47:35 -0400 Subject: [PATCH] GUACAMOLE-527: Clean up memory and logging. --- src/common-ssh/ssh.c | 18 ++++++++++-------- src/protocols/rdp/rdp_settings.c | 3 +++ src/protocols/ssh/settings.c | 2 ++ src/protocols/vnc/settings.c | 3 +++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/common-ssh/ssh.c b/src/common-ssh/ssh.c index 1327b03e..03c4d125 100644 --- a/src/common-ssh/ssh.c +++ b/src/common-ssh/ssh.c @@ -520,22 +520,22 @@ guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client, return NULL; } - /* Check known_hosts */ - /* Get known hosts file from user running guacd */ + /* Check known_hosts, start by getting known_hosts file of user running guacd */ struct passwd *pw = getpwuid(getuid()); - char *homedir = pw->pw_dir; - char *known_hosts = strcat(homedir, "/.ssh/known_hosts"); + const char *known_hosts = strcat(pw->pw_dir, "/.ssh/known_hosts"); LIBSSH2_KNOWNHOSTS *ssh_known_hosts = libssh2_knownhost_init(session); libssh2_knownhost_readfile(ssh_known_hosts, known_hosts, LIBSSH2_KNOWNHOST_FILE_OPENSSH); /* Add host key provided from settings */ if (host_key && strcmp(host_key, "") > 0) { - if (libssh2_knownhost_addc(ssh_known_hosts, hostname, NULL, host_key, strlen(host_key), + int kh_add = libssh2_knownhost_addc(ssh_known_hosts, hostname, NULL, host_key, strlen(host_key), NULL, 0, LIBSSH2_KNOWNHOST_TYPE_PLAIN|LIBSSH2_KNOWNHOST_KEYENC_BASE64| - host_key_type, NULL)) - guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, - "Failed to add host key to known hosts store for %s", hostname); + host_key_type, NULL); + + if (kh_add) + guac_client_log(client, GUAC_LOG_WARNING, "Failed to add provided host key" + " to known hosts store for %s. Error was %d", hostname, kh_add); } @@ -556,6 +556,8 @@ guac_common_ssh_session* guac_common_ssh_create_session(guac_client* client, LIBSSH2_KNOWNHOST_KEYENC_RAW, &host); + libssh2_knownhost_free(ssh_known_hosts); + switch (kh_check) { case LIBSSH2_KNOWNHOST_CHECK_MATCH: guac_client_log(client, GUAC_LOG_DEBUG, diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index 78afe374..65e79e6b 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -860,6 +860,8 @@ guac_rdp_settings* guac_rdp_parse_args(guac_user* user, settings->sftp_host_key = NULL; } + free(str_host_key_type); + } /* Port for SFTP connection */ @@ -1039,6 +1041,7 @@ void guac_rdp_settings_free(guac_rdp_settings* settings) { /* Free SFTP settings */ free(settings->sftp_directory); free(settings->sftp_root_directory); + free(settings->sftp_host_key); free(settings->sftp_hostname); free(settings->sftp_passphrase); free(settings->sftp_password); diff --git a/src/protocols/ssh/settings.c b/src/protocols/ssh/settings.c index d49a16c1..119d725d 100644 --- a/src/protocols/ssh/settings.c +++ b/src/protocols/ssh/settings.c @@ -278,6 +278,8 @@ guac_ssh_settings* guac_ssh_parse_args(guac_user* user, "Ignoring host key.", str_host_key_type); settings->host_key = NULL; } + + free(str_host_key_type); } settings->username = diff --git a/src/protocols/vnc/settings.c b/src/protocols/vnc/settings.c index 509a067b..5f82b39b 100644 --- a/src/protocols/vnc/settings.c +++ b/src/protocols/vnc/settings.c @@ -446,6 +446,8 @@ guac_vnc_settings* guac_vnc_parse_args(guac_user* user, settings->sftp_host_key = NULL; } + free(str_host_key_type); + } /* Port for SFTP connection */ @@ -541,6 +543,7 @@ void guac_vnc_settings_free(guac_vnc_settings* settings) { /* Free SFTP settings */ free(settings->sftp_directory); free(settings->sftp_root_directory); + free(settings->sftp_host_key); free(settings->sftp_hostname); free(settings->sftp_passphrase); free(settings->sftp_password);