From c5fd72bb98769fc06ea5779cc7c3c8579dbf0467 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 1 Feb 2016 15:12:47 -0800 Subject: [PATCH] GUAC-1477: Ensure any fd_set used by guac_socket is always properly initialized. --- src/guacd/socket-ssl.c | 8 ++++---- src/libguac/socket-fd.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/guacd/socket-ssl.c b/src/guacd/socket-ssl.c index adbbd94a..751286d8 100644 --- a/src/guacd/socket-ssl.c +++ b/src/guacd/socket-ssl.c @@ -77,6 +77,10 @@ static int __guac_socket_ssl_select_handler(guac_socket* socket, int usec_timeou struct timeval timeout; int retval; + /* Initialize fd_set with single underlying file descriptor */ + FD_ZERO(&fds); + FD_SET(data->fd, &fds); + /* No timeout if usec_timeout is negative */ if (usec_timeout < 0) retval = select(data->fd + 1, &fds, NULL, NULL, NULL); @@ -85,10 +89,6 @@ static int __guac_socket_ssl_select_handler(guac_socket* socket, int usec_timeou else { timeout.tv_sec = usec_timeout/1000000; timeout.tv_usec = usec_timeout%1000000; - - FD_ZERO(&fds); - FD_SET(data->fd, &fds); - retval = select(data->fd + 1, &fds, NULL, NULL, &timeout); } diff --git a/src/libguac/socket-fd.c b/src/libguac/socket-fd.c index 13c66edd..5bd9bf34 100644 --- a/src/libguac/socket-fd.c +++ b/src/libguac/socket-fd.c @@ -92,6 +92,10 @@ int __guac_socket_fd_select_handler(guac_socket* socket, int usec_timeout) { struct timeval timeout; int retval; + /* Initialize fd_set with single underlying file descriptor */ + FD_ZERO(&fds); + FD_SET(data->fd, &fds); + /* No timeout if usec_timeout is negative */ if (usec_timeout < 0) retval = select(data->fd + 1, &fds, NULL, NULL, NULL); @@ -100,10 +104,6 @@ int __guac_socket_fd_select_handler(guac_socket* socket, int usec_timeout) { else { timeout.tv_sec = usec_timeout/1000000; timeout.tv_usec = usec_timeout%1000000; - - FD_ZERO(&fds); - FD_SET(data->fd, &fds); - retval = select(data->fd + 1, &fds, NULL, NULL, &timeout); }