mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-05 20:55:46 +03:00
fix bug #0000002 : in_socket_buffer and out_socket_buffer memleak +
"g" and "p" O(1) memleak. git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@134 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -441,7 +441,7 @@ void ssh_print_bignum(char *which,bignum num);
|
|||||||
void dh_generate_x(SSH_SESSION *session);
|
void dh_generate_x(SSH_SESSION *session);
|
||||||
void dh_generate_y(SSH_SESSION *session);
|
void dh_generate_y(SSH_SESSION *session);
|
||||||
void dh_generate_f(SSH_SESSION *session);
|
void dh_generate_f(SSH_SESSION *session);
|
||||||
|
void ssh_crypto_finalize();
|
||||||
STRING *dh_get_e(SSH_SESSION *session);
|
STRING *dh_get_e(SSH_SESSION *session);
|
||||||
STRING *dh_get_f(SSH_SESSION *session);
|
STRING *dh_get_f(SSH_SESSION *session);
|
||||||
void dh_import_f(SSH_SESSION *session,STRING *f_string);
|
void dh_import_f(SSH_SESSION *session,STRING *f_string);
|
||||||
|
15
libssh/dh.c
15
libssh/dh.c
@@ -65,6 +65,7 @@ static unsigned char p_value[] = {
|
|||||||
static unsigned long g_int = 2 ; /* G is defined as 2 by the ssh2 standards */
|
static unsigned long g_int = 2 ; /* G is defined as 2 by the ssh2 standards */
|
||||||
static bignum g;
|
static bignum g;
|
||||||
static bignum p;
|
static bignum p;
|
||||||
|
static int ssh_crypto_inited=0;
|
||||||
|
|
||||||
/* maybe it might be enhanced .... */
|
/* maybe it might be enhanced .... */
|
||||||
/* XXX Do it. */
|
/* XXX Do it. */
|
||||||
@@ -84,10 +85,10 @@ int ssh_get_random(void *where, int len, int strong){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* it inits the values g and p which are used for DH key agreement */
|
/* it inits the values g and p which are used for DH key agreement */
|
||||||
void ssh_crypto_init(){
|
void ssh_crypto_init(){
|
||||||
static int init=0;
|
if(ssh_crypto_inited == 0){
|
||||||
if(!init){
|
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
gcry_check_version(NULL);
|
gcry_check_version(NULL);
|
||||||
if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P,0))
|
if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P,0))
|
||||||
@@ -105,7 +106,15 @@ void ssh_crypto_init(){
|
|||||||
bignum_bin2bn(p_value,P_LEN,p);
|
bignum_bin2bn(p_value,P_LEN,p);
|
||||||
OpenSSL_add_all_algorithms();
|
OpenSSL_add_all_algorithms();
|
||||||
#endif
|
#endif
|
||||||
init++;
|
ssh_crypto_inited++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ssh_crypto_finalize(){
|
||||||
|
if(ssh_crypto_inited){
|
||||||
|
bignum_free(g);
|
||||||
|
bignum_free(p);
|
||||||
|
ssh_crypto_inited=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ MA 02111-1307, USA. */
|
|||||||
|
|
||||||
int ssh_finalize()
|
int ssh_finalize()
|
||||||
{
|
{
|
||||||
|
ssh_crypto_finalize();
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
gcry_control(GCRYCTL_TERM_SECMEM);
|
gcry_control(GCRYCTL_TERM_SECMEM);
|
||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
|
@@ -58,6 +58,10 @@ void ssh_cleanup(SSH_SESSION *session){
|
|||||||
buffer_free(session->in_buffer);
|
buffer_free(session->in_buffer);
|
||||||
if(session->out_buffer)
|
if(session->out_buffer)
|
||||||
buffer_free(session->out_buffer);
|
buffer_free(session->out_buffer);
|
||||||
|
if(session->in_socket_buffer)
|
||||||
|
buffer_free(session->in_socket_buffer);
|
||||||
|
if(session->out_socket_buffer)
|
||||||
|
buffer_free(session->out_socket_buffer);
|
||||||
if(session->banner)
|
if(session->banner)
|
||||||
free(session->banner);
|
free(session->banner);
|
||||||
if(session->options)
|
if(session->options)
|
||||||
|
19
sample.c
19
sample.c
@@ -391,7 +391,7 @@ int main(int argc, char **argv){
|
|||||||
if(ssh_connect(session)){
|
if(ssh_connect(session)){
|
||||||
fprintf(stderr,"Connection failed : %s\n",ssh_get_error(session));
|
fprintf(stderr,"Connection failed : %s\n",ssh_get_error(session));
|
||||||
ssh_disconnect(session);
|
ssh_disconnect(session);
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
state=ssh_is_server_known(session);
|
state=ssh_is_server_known(session);
|
||||||
@@ -404,16 +404,16 @@ int main(int argc, char **argv){
|
|||||||
ssh_print_hexa("Public key hash",hash,MD5_DIGEST_LEN);
|
ssh_print_hexa("Public key hash",hash,MD5_DIGEST_LEN);
|
||||||
fprintf(stderr,"For security reason, connection will be stopped\n");
|
fprintf(stderr,"For security reason, connection will be stopped\n");
|
||||||
ssh_disconnect(session);
|
ssh_disconnect(session);
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
exit(-1);
|
exit(-1);
|
||||||
case SSH_SERVER_FOUND_OTHER:
|
case SSH_SERVER_FOUND_OTHER:
|
||||||
fprintf(stderr,"The host key for this server was not found but an other type of key exists.\n");
|
fprintf(stderr,"The host key for this server was not found but an other type of key exists.\n");
|
||||||
fprintf(stderr,"An attacker might change the default server key to confuse your client"
|
fprintf(stderr,"An attacker might change the default server key to confuse your client"
|
||||||
"into thinking the key does not exist\n"
|
"into thinking the key does not exist\n"
|
||||||
"We advise you to rerun the client with -d or -r for more safety.\n");
|
"We advise you to rerun the client with -d or -r for more safety.\n");
|
||||||
ssh_disconnect(session);
|
ssh_disconnect(session);
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
exit(-1);
|
exit(-1);
|
||||||
case SSH_SERVER_NOT_KNOWN:
|
case SSH_SERVER_NOT_KNOWN:
|
||||||
fprintf(stderr,"The server is unknown. Do you trust the host key ?\n");
|
fprintf(stderr,"The server is unknown. Do you trust the host key ?\n");
|
||||||
ssh_get_pubkey_hash(session,hash);
|
ssh_get_pubkey_hash(session,hash);
|
||||||
@@ -434,7 +434,7 @@ int main(int argc, char **argv){
|
|||||||
case SSH_SERVER_ERROR:
|
case SSH_SERVER_ERROR:
|
||||||
fprintf(stderr,"%s",ssh_get_error(session));
|
fprintf(stderr,"%s",ssh_get_error(session));
|
||||||
ssh_disconnect(session);
|
ssh_disconnect(session);
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,7 +442,7 @@ int main(int argc, char **argv){
|
|||||||
auth=ssh_userauth_autopubkey(session);
|
auth=ssh_userauth_autopubkey(session);
|
||||||
if(auth==SSH_AUTH_ERROR){
|
if(auth==SSH_AUTH_ERROR){
|
||||||
fprintf(stderr,"Authenticating with pubkey: %s\n",ssh_get_error(session));
|
fprintf(stderr,"Authenticating with pubkey: %s\n",ssh_get_error(session));
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
banner=ssh_get_issue_banner(session);
|
banner=ssh_get_issue_banner(session);
|
||||||
@@ -455,7 +455,7 @@ int main(int argc, char **argv){
|
|||||||
if(auth==SSH_AUTH_ERROR){
|
if(auth==SSH_AUTH_ERROR){
|
||||||
fprintf(stderr,"authenticating with keyb-interactive: %s\n",
|
fprintf(stderr,"authenticating with keyb-interactive: %s\n",
|
||||||
ssh_get_error(session));
|
ssh_get_error(session));
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -464,13 +464,12 @@ int main(int argc, char **argv){
|
|||||||
if(ssh_userauth_password(session,NULL,password) != SSH_AUTH_SUCCESS){
|
if(ssh_userauth_password(session,NULL,password) != SSH_AUTH_SUCCESS){
|
||||||
fprintf(stderr,"Authentication failed: %s\n",ssh_get_error(session));
|
fprintf(stderr,"Authentication failed: %s\n",ssh_get_error(session));
|
||||||
ssh_disconnect(session);
|
ssh_disconnect(session);
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(password,0,strlen(password));
|
memset(password,0,strlen(password));
|
||||||
}
|
}
|
||||||
ssh_say(1,"Authentication success\n");
|
ssh_say(1,"Authentication success\n");
|
||||||
printf("%s\n",argv[0]);
|
|
||||||
if(strstr(argv[0],"sftp")){
|
if(strstr(argv[0],"sftp")){
|
||||||
sftp=1;
|
sftp=1;
|
||||||
ssh_say(1,"doing sftp instead\n");
|
ssh_say(1,"doing sftp instead\n");
|
||||||
|
Reference in New Issue
Block a user