Fixed the memory leak in in libssh2_userauth_hostbased_fromfile_ex() that

Jean-Louis Charton found. Additional minor indent and comment edits.
This commit is contained in:
Daniel Stenberg 2009-03-28 21:31:53 +00:00
parent 55744f8f34
commit 60ee30b6c9
2 changed files with 14 additions and 2 deletions

6
NEWS
View File

@ -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 * Renamed the functions in src/transport.c to be _libssh2_transport_ prefixed
and introduced a transport.h header. and introduced a transport.h header.

View File

@ -468,6 +468,8 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION *session, const char *username,
* file_read_publickey * file_read_publickey
* *
* Read a public key from an id_???.pub style file * Read a public key from an id_???.pub style file
*
* Returns an allocated string in *pubkeydata on success.
*/ */
static int static int
file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, 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; sp2 = pubkey + pubkey_len;
} }
if (libssh2_base64_decode if (libssh2_base64_decode(session, (char **) &tmp, &tmp_len,
(session, (char **) &tmp, &tmp_len, (char *) sp1, sp2 - sp1)) { (char *) sp1, sp2 - sp1)) {
libssh2_error(session, LIBSSH2_ERROR_FILE, libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid key data, not base64 encoded", 0); "Invalid key data, not base64 encoded", 0);
LIBSSH2_FREE(session, pubkey); LIBSSH2_FREE(session, pubkey);
@ -672,6 +674,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
if (!session->userauth_host_packet) { if (!session->userauth_host_packet) {
LIBSSH2_FREE(session, session->userauth_host_method); LIBSSH2_FREE(session, session->userauth_host_method);
session->userauth_host_method = NULL; session->userauth_host_method = NULL;
LIBSSH2_FREE(session, pubkeydata);
return -1; return -1;
} }
@ -681,11 +684,13 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
memcpy(session->userauth_host_s, username, username_len); memcpy(session->userauth_host_s, username, username_len);
session->userauth_host_s += username_len; session->userauth_host_s += username_len;
/* TODO: change the hideous '14' to a nice defined */
_libssh2_htonu32(session->userauth_host_s, 14); _libssh2_htonu32(session->userauth_host_s, 14);
session->userauth_host_s += 4; session->userauth_host_s += 4;
memcpy(session->userauth_host_s, "ssh-connection", 14); memcpy(session->userauth_host_s, "ssh-connection", 14);
session->userauth_host_s += 14; session->userauth_host_s += 14;
/* TODO: change the hideous '9' to a nice defined */
_libssh2_htonu32(session->userauth_host_s, 9); _libssh2_htonu32(session->userauth_host_s, 9);
session->userauth_host_s += 4; session->userauth_host_s += 4;
memcpy(session->userauth_host_s, "hostbased", 9); memcpy(session->userauth_host_s, "hostbased", 9);
@ -702,6 +707,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
session->userauth_host_s += 4; session->userauth_host_s += 4;
memcpy(session->userauth_host_s, pubkeydata, pubkeydata_len); memcpy(session->userauth_host_s, pubkeydata, pubkeydata_len);
session->userauth_host_s += pubkeydata_len; session->userauth_host_s += pubkeydata_len;
LIBSSH2_FREE(session, pubkeydata);
_libssh2_htonu32(session->userauth_host_s, hostname_len); _libssh2_htonu32(session->userauth_host_s, hostname_len);
session->userauth_host_s += 4; session->userauth_host_s += 4;