GUAC-1477: Ensure any fd_set used by guac_socket is always properly initialized.

This commit is contained in:
Michael Jumper 2016-02-01 15:12:47 -08:00
parent d0be90e711
commit c5fd72bb98
2 changed files with 8 additions and 8 deletions

View File

@ -77,6 +77,10 @@ static int __guac_socket_ssl_select_handler(guac_socket* socket, int usec_timeou
struct timeval timeout; struct timeval timeout;
int retval; 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 */ /* No timeout if usec_timeout is negative */
if (usec_timeout < 0) if (usec_timeout < 0)
retval = select(data->fd + 1, &fds, NULL, NULL, NULL); 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 { else {
timeout.tv_sec = usec_timeout/1000000; timeout.tv_sec = usec_timeout/1000000;
timeout.tv_usec = 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); retval = select(data->fd + 1, &fds, NULL, NULL, &timeout);
} }

View File

@ -92,6 +92,10 @@ int __guac_socket_fd_select_handler(guac_socket* socket, int usec_timeout) {
struct timeval timeout; struct timeval timeout;
int retval; 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 */ /* No timeout if usec_timeout is negative */
if (usec_timeout < 0) if (usec_timeout < 0)
retval = select(data->fd + 1, &fds, NULL, NULL, NULL); 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 { else {
timeout.tv_sec = usec_timeout/1000000; timeout.tv_sec = usec_timeout/1000000;
timeout.tv_usec = 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); retval = select(data->fd + 1, &fds, NULL, NULL, &timeout);
} }