aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libssh/client.c2
-rw-r--r--libssh/packet.c10
2 files changed, 9 insertions, 3 deletions
diff --git a/libssh/client.c b/libssh/client.c
index da4636a2..9af4e627 100644
--- a/libssh/client.c
+++ b/libssh/client.c
@@ -36,7 +36,7 @@ char *ssh_get_banner(SSH_SESSION *session){
char buffer[128];
int i = 0;
while (i < 127) {
- if(session->fd >=0 && read(session->fd, &buffer[i], 1)<=0){
+ if(session->fd <0 || read(session->fd, &buffer[i], 1)<=0){
ssh_set_error(session,SSH_FATAL,"Remote host closed connection");
return NULL;
}
diff --git a/libssh/packet.c b/libssh/packet.c
index 900671dd..61034979 100644
--- a/libssh/packet.c
+++ b/libssh/packet.c
@@ -101,7 +101,8 @@ static int socket_read(SSH_SESSION *session,int len){
if(r<=0){
ssh_set_error(session,SSH_FATAL,
(r==0)?"Connection closed by remote host" : "Error reading socket");
- close(session->fd);
+ if(session->fd>=0)
+ close(session->fd);
session->fd=-1;
session->data_except=1;
return SSH_ERROR;
@@ -359,8 +360,13 @@ static int packet_nonblocking_flush(SSH_SESSION *session){
int except, can_write;
int w;
ssh_fd_poll(session,&can_write,&except); /* internally sets data_to_write */
+ if(session->fd<0){
+ session->alive=0;
+ ssh_set_error(session,SSH_FATAL,"Writing packet : error on socket (or connection closed): %s",strerror(errno));
+ return SSH_ERROR;
+ }
while(session->data_to_write && buffer_get_rest_len(session->out_socket_buffer)>0){
- if(session->fd<0){
+ if(session->fd>=0){
w=write(session->fd,buffer_get_rest(session->out_socket_buffer),
buffer_get_rest_len(session->out_socket_buffer));
session->data_to_write=0;