necouchman commented on code in PR #643:
URL: https://github.com/apache/guacamole-server/pull/643#discussion_r2985039825
##########
src/libguac/tcp.c:
##########
@@ -97,20 +97,33 @@ int guac_tcp_connect(const char* hostname, const char*
port, const int timeout)
continue;
}
- /* Structure that stores our timeout setting. */
struct timeval tv;
tv.tv_sec = timeout;
tv.tv_usec = 0;
/* Connect and wait for timeout */
if ((retval = connect(fd, current_address->ai_addr,
current_address->ai_addrlen)) < 0) {
- if (errno == EINPROGRESS) {
- /* Set up timeout. */
+ /* If connect() is in progress (EINPROGRESS) or interrupted by a
signal
+ * (EINTR), wait for the socket to become writable and check
SO_ERROR. */
+ if (errno == EINPROGRESS || errno == EINTR) {
+
+ /* Prevent overflowing fd_set. */
+ if (fd >= FD_SETSIZE) {
+ guac_error = GUAC_STATUS_INVALID_ARGUMENT;
+ guac_error_message = "File descriptor exceeds FD_SETSIZE.";
+ close(fd);
+ fd = -1;
+ continue;
+ }
+
fd_set fdset;
FD_ZERO(&fdset);
FD_SET(fd, &fdset);
-
- retval = select(fd + 1, NULL, &fdset, NULL, &tv);
+
+ /* Linux (kernel/glibc verified): select() does not modify
fd_set on -1,
+ and updates struct timeval to reflect elapsed time on
EINTR, so
+ neither needs reinitialization on retry. */
Review Comment:
This line appears to have a couple of tabs instead of spaces.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]