fix bug 0000015 about memory leak in server path
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@180 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
родитель
5758188467
Коммит
d477025000
@ -84,6 +84,8 @@ static SSH_MESSAGE *handle_userauth_request(SSH_SESSION *session){
|
|||||||
free(user);
|
free(user);
|
||||||
service_c=string_to_char(service);
|
service_c=string_to_char(service);
|
||||||
method_c=string_to_char(method);
|
method_c=string_to_char(method);
|
||||||
|
free(service);
|
||||||
|
free(method);
|
||||||
ssh_say(2,"auth request for service %s, method %s for user '%s'\n",service_c,method_c,
|
ssh_say(2,"auth request for service %s, method %s for user '%s'\n",service_c,method_c,
|
||||||
msg->auth_request.username);
|
msg->auth_request.username);
|
||||||
free(service_c);
|
free(service_c);
|
||||||
@ -182,10 +184,12 @@ static SSH_MESSAGE *handle_channel_request_open(SSH_SESSION *session){
|
|||||||
msg->channel_request_open.packet_size=ntohl(packet);
|
msg->channel_request_open.packet_size=ntohl(packet);
|
||||||
if(!strcmp(type_c,"session")){
|
if(!strcmp(type_c,"session")){
|
||||||
msg->channel_request_open.type=SSH_CHANNEL_SESSION;
|
msg->channel_request_open.type=SSH_CHANNEL_SESSION;
|
||||||
|
free(type_c);
|
||||||
leave_function();
|
leave_function();
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
msg->channel_request_open.type=SSH_CHANNEL_UNKNOWN;
|
msg->channel_request_open.type=SSH_CHANNEL_UNKNOWN;
|
||||||
|
free(type_c);
|
||||||
leave_function();
|
leave_function();
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
@ -247,6 +251,7 @@ static SSH_MESSAGE *handle_channel_request(SSH_SESSION *session){
|
|||||||
if(!strcmp(type_c,"pty-req")){
|
if(!strcmp(type_c,"pty-req")){
|
||||||
STRING *term;
|
STRING *term;
|
||||||
char *term_c;
|
char *term_c;
|
||||||
|
free(type_c);
|
||||||
term=buffer_get_ssh_string(session->in_buffer);
|
term=buffer_get_ssh_string(session->in_buffer);
|
||||||
term_c=string_to_char(term);
|
term_c=string_to_char(term);
|
||||||
free(term);
|
free(term);
|
||||||
@ -267,6 +272,7 @@ static SSH_MESSAGE *handle_channel_request(SSH_SESSION *session){
|
|||||||
if(!strcmp(type_c,"subsystem")){
|
if(!strcmp(type_c,"subsystem")){
|
||||||
STRING *subsys;
|
STRING *subsys;
|
||||||
char *subsys_c;
|
char *subsys_c;
|
||||||
|
free(type_c);
|
||||||
subsys=buffer_get_ssh_string(session->in_buffer);
|
subsys=buffer_get_ssh_string(session->in_buffer);
|
||||||
subsys_c=string_to_char(subsys);
|
subsys_c=string_to_char(subsys);
|
||||||
free(subsys);
|
free(subsys);
|
||||||
@ -276,12 +282,14 @@ static SSH_MESSAGE *handle_channel_request(SSH_SESSION *session){
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
if(!strcmp(type_c,"shell")){
|
if(!strcmp(type_c,"shell")){
|
||||||
|
free(type_c);
|
||||||
msg->channel_request.type=SSH_CHANNEL_REQUEST_SHELL;
|
msg->channel_request.type=SSH_CHANNEL_REQUEST_SHELL;
|
||||||
leave_function();
|
leave_function();
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
if(!strcmp(type_c,"exec")){
|
if(!strcmp(type_c,"exec")){
|
||||||
STRING *cmd=buffer_get_ssh_string(session->in_buffer);
|
STRING *cmd=buffer_get_ssh_string(session->in_buffer);
|
||||||
|
free(type_c);
|
||||||
msg->channel_request.type=SSH_CHANNEL_REQUEST_EXEC;
|
msg->channel_request.type=SSH_CHANNEL_REQUEST_EXEC;
|
||||||
msg->channel_request.command=string_to_char(cmd);
|
msg->channel_request.command=string_to_char(cmd);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
@ -290,6 +298,7 @@ static SSH_MESSAGE *handle_channel_request(SSH_SESSION *session){
|
|||||||
}
|
}
|
||||||
|
|
||||||
msg->channel_request.type=SSH_CHANNEL_UNKNOWN;
|
msg->channel_request.type=SSH_CHANNEL_UNKNOWN;
|
||||||
|
free(type_c);
|
||||||
leave_function();
|
leave_function();
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,7 @@ SSH_SESSION *ssh_bind_accept(SSH_BIND *ssh_bind){
|
|||||||
session=ssh_new();
|
session=ssh_new();
|
||||||
session->server=1;
|
session->server=1;
|
||||||
session->version=2;
|
session->version=2;
|
||||||
|
ssh_socket_free(session->socket);
|
||||||
session->socket=ssh_socket_new(session);
|
session->socket=ssh_socket_new(session);
|
||||||
ssh_socket_set_fd(session->socket,fd);
|
ssh_socket_set_fd(session->socket,fd);
|
||||||
session->options=ssh_options_copy(ssh_bind->options);
|
session->options=ssh_options_copy(ssh_bind->options);
|
||||||
@ -175,6 +176,8 @@ void ssh_bind_free(SSH_BIND *ssh_bind){
|
|||||||
if(ssh_bind->bindfd>=0)
|
if(ssh_bind->bindfd>=0)
|
||||||
close(ssh_bind->bindfd);
|
close(ssh_bind->bindfd);
|
||||||
ssh_bind->bindfd=-1;
|
ssh_bind->bindfd=-1;
|
||||||
|
if(ssh_bind->options)
|
||||||
|
ssh_options_free(ssh_bind->options);
|
||||||
free(ssh_bind);
|
free(ssh_bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,6 +226,7 @@ static int dh_handshake_server(SSH_SESSION *session){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
dh_import_e(session,e);
|
dh_import_e(session,e);
|
||||||
|
free(e);
|
||||||
dh_generate_y(session);
|
dh_generate_y(session);
|
||||||
dh_generate_f(session);
|
dh_generate_f(session);
|
||||||
f=dh_get_f(session);
|
f=dh_get_f(session);
|
||||||
|
@ -447,6 +447,8 @@ void crypto_free(CRYPTO *crypto){
|
|||||||
bignum_free(crypto->f);
|
bignum_free(crypto->f);
|
||||||
if(crypto->x)
|
if(crypto->x)
|
||||||
bignum_free(crypto->x);
|
bignum_free(crypto->x);
|
||||||
|
if(crypto->y)
|
||||||
|
bignum_free(crypto->y);
|
||||||
if(crypto->k)
|
if(crypto->k)
|
||||||
bignum_free(crypto->k);
|
bignum_free(crypto->k);
|
||||||
/* lot of other things */
|
/* lot of other things */
|
||||||
@ -509,6 +511,7 @@ int crypt_set_algorithms(SSH_SESSION *session){
|
|||||||
// TODO Obviously too much cut and paste here
|
// TODO Obviously too much cut and paste here
|
||||||
int crypt_set_algorithms_server(SSH_SESSION *session){
|
int crypt_set_algorithms_server(SSH_SESSION *session){
|
||||||
/* we must scan the kex entries to find crypto algorithms and set their appropriate structure */
|
/* we must scan the kex entries to find crypto algorithms and set their appropriate structure */
|
||||||
|
enter_function();
|
||||||
int i=0;
|
int i=0;
|
||||||
/* out */
|
/* out */
|
||||||
char *server=session->server_kex.methods[SSH_CRYPT_S_C];
|
char *server=session->server_kex.methods[SSH_CRYPT_S_C];
|
||||||
@ -516,16 +519,21 @@ int crypt_set_algorithms_server(SSH_SESSION *session){
|
|||||||
char *match=ssh_find_matching(client,server);
|
char *match=ssh_find_matching(client,server);
|
||||||
if(!match){
|
if(!match){
|
||||||
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server : no matching algorithm function found for %s",server);
|
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server : no matching algorithm function found for %s",server);
|
||||||
|
free(match);
|
||||||
|
leave_function();
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
while(ssh_ciphertab[i].name && strcmp(match,ssh_ciphertab[i].name))
|
while(ssh_ciphertab[i].name && strcmp(match,ssh_ciphertab[i].name))
|
||||||
i++;
|
i++;
|
||||||
if(!ssh_ciphertab[i].name){
|
if(!ssh_ciphertab[i].name){
|
||||||
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server : no crypto algorithm function found for %s",server);
|
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server : no crypto algorithm function found for %s",server);
|
||||||
|
free(match);
|
||||||
|
leave_function();
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
ssh_log(session,SSH_LOG_PACKET,"Set output algorithm %s",match);
|
ssh_log(session,SSH_LOG_PACKET,"Set output algorithm %s",match);
|
||||||
session->next_crypto->out_cipher=cipher_new(i);
|
session->next_crypto->out_cipher=cipher_new(i);
|
||||||
|
free(match);
|
||||||
i=0;
|
i=0;
|
||||||
/* in */
|
/* in */
|
||||||
client=session->client_kex.methods[SSH_CRYPT_C_S];
|
client=session->client_kex.methods[SSH_CRYPT_C_S];
|
||||||
@ -533,16 +541,21 @@ int crypt_set_algorithms_server(SSH_SESSION *session){
|
|||||||
match=ssh_find_matching(client,server);
|
match=ssh_find_matching(client,server);
|
||||||
if(!match){
|
if(!match){
|
||||||
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server : no matching algorithm function found for %s",server);
|
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server : no matching algorithm function found for %s",server);
|
||||||
|
free(match);
|
||||||
|
leave_function();
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
while(ssh_ciphertab[i].name && strcmp(match,ssh_ciphertab[i].name))
|
while(ssh_ciphertab[i].name && strcmp(match,ssh_ciphertab[i].name))
|
||||||
i++;
|
i++;
|
||||||
if(!ssh_ciphertab[i].name){
|
if(!ssh_ciphertab[i].name){
|
||||||
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server : no crypto algorithm function found for %s",server);
|
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server : no crypto algorithm function found for %s",server);
|
||||||
|
free(match);
|
||||||
|
leave_function();
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
ssh_log(session,SSH_LOG_PACKET,"Set input algorithm %s",match);
|
ssh_log(session,SSH_LOG_PACKET,"Set input algorithm %s",match);
|
||||||
session->next_crypto->in_cipher=cipher_new(i);
|
session->next_crypto->in_cipher=cipher_new(i);
|
||||||
|
free(match);
|
||||||
/* compression */
|
/* compression */
|
||||||
client=session->client_kex.methods[SSH_CRYPT_C_S];
|
client=session->client_kex.methods[SSH_CRYPT_C_S];
|
||||||
server=session->server_kex.methods[SSH_CRYPT_C_S];
|
server=session->server_kex.methods[SSH_CRYPT_C_S];
|
||||||
@ -551,6 +564,7 @@ int crypt_set_algorithms_server(SSH_SESSION *session){
|
|||||||
ssh_log(session,SSH_LOG_PACKET,"enabling C->S compression");
|
ssh_log(session,SSH_LOG_PACKET,"enabling C->S compression");
|
||||||
session->next_crypto->do_compress_in=1;
|
session->next_crypto->do_compress_in=1;
|
||||||
}
|
}
|
||||||
|
free(match);
|
||||||
|
|
||||||
client=session->client_kex.methods[SSH_CRYPT_S_C];
|
client=session->client_kex.methods[SSH_CRYPT_S_C];
|
||||||
server=session->server_kex.methods[SSH_CRYPT_S_C];
|
server=session->server_kex.methods[SSH_CRYPT_S_C];
|
||||||
@ -559,7 +573,8 @@ int crypt_set_algorithms_server(SSH_SESSION *session){
|
|||||||
ssh_log(session,SSH_LOG_PACKET,"enabling S->C compression\n");
|
ssh_log(session,SSH_LOG_PACKET,"enabling S->C compression\n");
|
||||||
session->next_crypto->do_compress_out=1;
|
session->next_crypto->do_compress_out=1;
|
||||||
}
|
}
|
||||||
|
free(match);
|
||||||
|
|
||||||
server=session->server_kex.methods[SSH_HOSTKEYS];
|
server=session->server_kex.methods[SSH_HOSTKEYS];
|
||||||
client=session->client_kex.methods[SSH_HOSTKEYS];
|
client=session->client_kex.methods[SSH_HOSTKEYS];
|
||||||
match=ssh_find_matching(client,server);
|
match=ssh_find_matching(client,server);
|
||||||
@ -569,7 +584,11 @@ int crypt_set_algorithms_server(SSH_SESSION *session){
|
|||||||
session->hostkeys=TYPE_RSA;
|
session->hostkeys=TYPE_RSA;
|
||||||
else {
|
else {
|
||||||
ssh_set_error(session,SSH_FATAL,"cannot know what %s is into %s",match,server);
|
ssh_set_error(session,SSH_FATAL,"cannot know what %s is into %s",match,server);
|
||||||
|
free(match);
|
||||||
|
leave_function();
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
free(match);
|
||||||
|
leave_function();
|
||||||
return SSH_OK;
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,9 @@ int main(int argc, char **argv){
|
|||||||
if(i>0)
|
if(i>0)
|
||||||
write(1,buffer_get(buf),buffer_get_len(buf));
|
write(1,buffer_get(buf),buffer_get_len(buf));
|
||||||
} while (i>0);
|
} while (i>0);
|
||||||
|
buffer_free(buf);
|
||||||
ssh_disconnect(session);
|
ssh_disconnect(session);
|
||||||
|
ssh_bind_free(ssh_bind);
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user