mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-02 01:17:52 +03:00
[socket] fix a segfault at disconnect
(cherry picked from commit 56394917b15e41603c641c22a4e29c33b096d673)
This commit is contained in:
17
src/socket.c
17
src/socket.c
@@ -246,8 +246,9 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
|
|||||||
s->read_wontblock=1;
|
s->read_wontblock=1;
|
||||||
r=ssh_socket_unbuffered_read(s,buffer,sizeof(buffer));
|
r=ssh_socket_unbuffered_read(s,buffer,sizeof(buffer));
|
||||||
if(r<0){
|
if(r<0){
|
||||||
if(p != NULL)
|
if(p != NULL) {
|
||||||
ssh_poll_set_events(p,ssh_poll_get_events(p) & ~POLLIN);
|
ssh_poll_remove_events(p, POLLIN);
|
||||||
|
}
|
||||||
if(s->callbacks && s->callbacks->exception){
|
if(s->callbacks && s->callbacks->exception){
|
||||||
s->callbacks->exception(
|
s->callbacks->exception(
|
||||||
SSH_SOCKET_EXCEPTION_ERROR,
|
SSH_SOCKET_EXCEPTION_ERROR,
|
||||||
@@ -255,7 +256,12 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(r==0){
|
if(r==0){
|
||||||
ssh_poll_set_events(p,ssh_poll_get_events(p) & ~POLLIN);
|
if(p != NULL) {
|
||||||
|
ssh_poll_remove_events(p, POLLIN);
|
||||||
|
}
|
||||||
|
if(p != NULL) {
|
||||||
|
ssh_poll_remove_events(p, POLLIN);
|
||||||
|
}
|
||||||
if(s->callbacks && s->callbacks->exception){
|
if(s->callbacks && s->callbacks->exception){
|
||||||
s->callbacks->exception(
|
s->callbacks->exception(
|
||||||
SSH_SOCKET_EXCEPTION_EOF,
|
SSH_SOCKET_EXCEPTION_EOF,
|
||||||
@@ -270,6 +276,9 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
|
|||||||
buffer_get_rest_len(s->in_buffer),
|
buffer_get_rest_len(s->in_buffer),
|
||||||
s->callbacks->userdata);
|
s->callbacks->userdata);
|
||||||
buffer_pass_bytes(s->in_buffer,r);
|
buffer_pass_bytes(s->in_buffer,r);
|
||||||
|
/* p may have been freed, so don't use it
|
||||||
|
* anymore in this function */
|
||||||
|
p = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,7 +299,9 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
|
|||||||
}
|
}
|
||||||
/* So, we can write data */
|
/* So, we can write data */
|
||||||
s->write_wontblock=1;
|
s->write_wontblock=1;
|
||||||
|
if(p != NULL) {
|
||||||
ssh_poll_remove_events(p, POLLOUT);
|
ssh_poll_remove_events(p, POLLOUT);
|
||||||
|
}
|
||||||
|
|
||||||
/* If buffered data is pending, write it */
|
/* If buffered data is pending, write it */
|
||||||
if(buffer_get_rest_len(s->out_buffer) > 0){
|
if(buffer_get_rest_len(s->out_buffer) > 0){
|
||||||
|
|||||||
Reference in New Issue
Block a user