1
1

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
Этот коммит содержится в:
Aris Adamantiadis 2005-10-26 16:59:16 +00:00
родитель bef09f8848
Коммит c53b6b907c
4 изменённых файлов: 35 добавлений и 10 удалений

Просмотреть файл

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

Просмотреть файл

@ -25,6 +25,7 @@ MA 02111-1307, USA. */
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include "libssh/priv.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 */
int channel_poll(CHANNEL *channel, int is_stderr){
BUFFER *buffer;
int r=0,w=0,err=0;
int r=0;
if(is_stderr)
buffer=channel->stderr_buffer;
else
buffer=channel->stdout_buffer;
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)
return r; // error or no data available
/* 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);
return r;
}
if(channel->remote_eof)
return 1;
@ -722,7 +719,7 @@ static int channel_protocol_select(CHANNEL **rchans, CHANNEL **wchans, CHANNEL *
for(i=0;rchans[i];++i){
chan=rchans[i];
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) ||
(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;
int fdmax=-1;
int i,fd;
int r;
/* don't allow NULL pointers */
if(!readchans)
readchans=&dummy;
@ -832,7 +830,14 @@ int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptch
}
}
/* 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){
if(FD_ISSET(readchans[i]->session->fd,&rset))
readchans[i]->session->data_to_read=1;

Просмотреть файл

@ -112,6 +112,21 @@ void ssh_set_fd_except(SSH_SESSION *session){
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 ret=0;
if(session->closed)

Просмотреть файл

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