From 60ee30b6c9e380f87ace00e423d83e06be76ba44 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 28 Mar 2009 21:31:53 +0000 Subject: [PATCH] Fixed the memory leak in in libssh2_userauth_hostbased_fromfile_ex() that Jean-Louis Charton found. Additional minor indent and comment edits. --- NEWS | 6 ++++++ src/userauth.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index f08dd7c..ca5b31d 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +- (Mar 28 2009) Daniel Stenberg: + + Jean-Louis Charton found a memory leak in + libssh2_userauth_hostbased_fromfile_ex() + +- (Mar 25 2009) Daniel Stenberg: * Renamed the functions in src/transport.c to be _libssh2_transport_ prefixed and introduced a transport.h header. diff --git a/src/userauth.c b/src/userauth.c index 610e513..c4e0c4f 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -468,6 +468,8 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION *session, const char *username, * file_read_publickey * * Read a public key from an id_???.pub style file + * + * Returns an allocated string in *pubkeydata on success. */ static int file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, @@ -553,8 +555,8 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, sp2 = pubkey + pubkey_len; } - if (libssh2_base64_decode - (session, (char **) &tmp, &tmp_len, (char *) sp1, sp2 - sp1)) { + if (libssh2_base64_decode(session, (char **) &tmp, &tmp_len, + (char *) sp1, sp2 - sp1)) { libssh2_error(session, LIBSSH2_ERROR_FILE, "Invalid key data, not base64 encoded", 0); LIBSSH2_FREE(session, pubkey); @@ -672,6 +674,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, if (!session->userauth_host_packet) { LIBSSH2_FREE(session, session->userauth_host_method); session->userauth_host_method = NULL; + LIBSSH2_FREE(session, pubkeydata); return -1; } @@ -681,11 +684,13 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, memcpy(session->userauth_host_s, username, username_len); session->userauth_host_s += username_len; + /* TODO: change the hideous '14' to a nice defined */ _libssh2_htonu32(session->userauth_host_s, 14); session->userauth_host_s += 4; memcpy(session->userauth_host_s, "ssh-connection", 14); session->userauth_host_s += 14; + /* TODO: change the hideous '9' to a nice defined */ _libssh2_htonu32(session->userauth_host_s, 9); session->userauth_host_s += 4; memcpy(session->userauth_host_s, "hostbased", 9); @@ -702,6 +707,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, session->userauth_host_s += 4; memcpy(session->userauth_host_s, pubkeydata, pubkeydata_len); session->userauth_host_s += pubkeydata_len; + LIBSSH2_FREE(session, pubkeydata); _libssh2_htonu32(session->userauth_host_s, hostname_len); session->userauth_host_s += 4;