1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-07 08:02:55 +03:00

resolved the infinite loop on exit (thanks giga for the hint).

I resolved a memory alloc problem into hmac_init (same kind that the one of md5_init).
It's still saying there is a memory corruption. Since the memory corruption happens before it is found (in malloc()), I'll have to run valgrind to locate it.


git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@46 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Aris Adamantiadis
2005-10-26 16:59:16 +00:00
parent bef09f8848
commit c53b6b907c
4 changed files with 35 additions and 10 deletions

View File

@@ -519,6 +519,11 @@ int channel_request_shell1(CHANNEL *channel);
int channel_request_exec1(CHANNEL *channel, char *cmd); int channel_request_exec1(CHANNEL *channel, char *cmd);
void channel_handle1(SSH_SESSION *session,int type); void channel_handle1(SSH_SESSION *session,int type);
int channel_write1(CHANNEL *channel, void *data, int len); int channel_write1(CHANNEL *channel, void *data, int len);
/* session.c */
int ssh_handle_packets(SSH_SESSION *session);
#ifdef __cplusplus #ifdef __cplusplus
} ; } ;
#endif #endif

View File

@@ -25,6 +25,7 @@ MA 02111-1307, USA. */
#include <netdb.h> #include <netdb.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include "libssh/priv.h" #include "libssh/priv.h"
#include "libssh/ssh2.h" #include "libssh/ssh2.h"
@@ -665,20 +666,16 @@ int channel_read(CHANNEL *channel, BUFFER *buffer,int bytes,int is_stderr){
/* returns the number of bytes available, 0 if nothing is currently available, -1 if error */ /* returns the number of bytes available, 0 if nothing is currently available, -1 if error */
int channel_poll(CHANNEL *channel, int is_stderr){ int channel_poll(CHANNEL *channel, int is_stderr){
BUFFER *buffer; BUFFER *buffer;
int r=0,w=0,err=0; int r=0;
if(is_stderr) if(is_stderr)
buffer=channel->stderr_buffer; buffer=channel->stderr_buffer;
else else
buffer=channel->stdout_buffer; buffer=channel->stdout_buffer;
while(buffer_get_rest_len(buffer)==0 && !channel->remote_eof){ while(buffer_get_rest_len(buffer)==0 && !channel->remote_eof){
r=ssh_fd_poll(channel->session,&w,&err); r=ssh_handle_packets(channel->session);
if(r<=0) if(r<=0)
return r; // error or no data available return r;
/* if an exception happened, it will be trapped by packet_read() */
if(packet_read(channel->session)||packet_translate(channel->session))
return -1;
packet_parse(channel->session);
} }
if(channel->remote_eof) if(channel->remote_eof)
return 1; return 1;
@@ -722,7 +719,7 @@ static int channel_protocol_select(CHANNEL **rchans, CHANNEL **wchans, CHANNEL *
for(i=0;rchans[i];++i){ for(i=0;rchans[i];++i){
chan=rchans[i]; chan=rchans[i];
while(chan->open && chan->session->data_to_read){ while(chan->open && chan->session->data_to_read){
channel_poll(chan,0); ssh_handle_packets(chan->session);
} }
if( (chan->stdout_buffer && buffer_get_len(chan->stdout_buffer)>0) || if( (chan->stdout_buffer && buffer_get_len(chan->stdout_buffer)>0) ||
(chan->stderr_buffer && buffer_get_len(chan->stderr_buffer)>0)){ (chan->stderr_buffer && buffer_get_len(chan->stderr_buffer)>0)){
@@ -770,6 +767,7 @@ int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptch
CHANNEL **rchans, **wchans, **echans; CHANNEL **rchans, **wchans, **echans;
int fdmax=-1; int fdmax=-1;
int i,fd; int i,fd;
int r;
/* don't allow NULL pointers */ /* don't allow NULL pointers */
if(!readchans) if(!readchans)
readchans=&dummy; readchans=&dummy;
@@ -832,7 +830,14 @@ int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptch
} }
} }
/* here we go */ /* here we go */
select(fdmax,&rset,&wset,&eset,timeout); r=select(fdmax,&rset,&wset,&eset,timeout);
/* leave if select was interrupted */
if(r==EINTR){
free(rchans);
free(wchans);
free(echans);
return SSH_EINTR;
}
for(i=0;readchans[i];++i){ for(i=0;readchans[i];++i){
if(FD_ISSET(readchans[i]->session->fd,&rset)) if(FD_ISSET(readchans[i]->session->fd,&rset))
readchans[i]->session->data_to_read=1; readchans[i]->session->data_to_read=1;

View File

@@ -112,6 +112,21 @@ void ssh_set_fd_except(SSH_SESSION *session){
session->data_except=1; session->data_except=1;
} }
/* looks if there is data to read on the socket and parse it. */
int ssh_handle_packets(SSH_SESSION *session){
int w,err,r;
do {
r=ssh_fd_poll(session,&w,&err);
if(r<=0)
return r; // error or no data available
/* if an exception happened, it will be trapped by packet_read() */
if(packet_read(session)||packet_translate(session))
return -1;
packet_parse(session);
} while(r>0);
return r;
}
int ssh_get_status(SSH_SESSION *session){ int ssh_get_status(SSH_SESSION *session){
int ret=0; int ret=0;
if(session->closed) if(session->closed)

View File

@@ -253,7 +253,7 @@ void md5_final(unsigned char *md,MD5CTX c){
HMACCTX hmac_init(const void *key, int len,int type){ HMACCTX hmac_init(const void *key, int len,int type){
HMACCTX ctx; HMACCTX ctx;
ctx=malloc(sizeof(HMAC_CTX)); ctx=malloc(sizeof(*ctx));
#ifndef OLD_CRYPTO #ifndef OLD_CRYPTO
HMAC_CTX_init(ctx); // openssl 0.9.7 requires it. HMAC_CTX_init(ctx); // openssl 0.9.7 requires it.
#endif #endif