bbennett-ks commented on code in PR #643:
URL: https://github.com/apache/guacamole-server/pull/643#discussion_r2981357501
##########
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. */
+ /* Structure that stores our timeout setting. On Linux, select()
updates
+ timeout with the remaining time on EINTR, so no need to
reinitialize on
+ retry. */
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);
+
+ GUAC_RETRY_EINTR(retval, select(fd + 1, NULL, &fdset, NULL,
&tv));
Review Comment:
I updated comments to clarify in the 2 places we call `select()`.
--
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]