]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
radius-socket: Fix timeout handling when waiting for responses
authorTobias Brunner <tobias@strongswan.org>
Wed, 17 Jun 2026 10:03:23 +0000 (12:03 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 23 Jul 2026 08:26:08 +0000 (10:26 +0200)
In case messages with unexpected IDs are received, the previous code
would always wait for the full timeout again.

src/libradius/radius_socket.c

index 4b93fbda18b6891173804ddc0057d35027214ab0..a1ee0016762855420b981e51b638e32ad86b7875 100644 (file)
@@ -200,16 +200,27 @@ static status_t receive_response(int fd, int timeout, uint8_t id,
                                                                 radius_message_t **response)
 {
        radius_message_t *msg;
+       timeval_t deadline, now, diff;
        char buf[4096];
-       int res;
+       int res, remaining;
        struct pollfd pfd = {
                .fd = fd,
                .events = POLLIN,
        };
 
+       time_monotonic(&deadline);
+       timeval_add_ms(&deadline, timeout);
+
        while (TRUE)
        {
-               res = poll(&pfd, 1, timeout);
+               time_monotonic(&now);
+               timersub(&deadline, &now, &diff);
+               remaining = diff.tv_sec * 1000 + diff.tv_usec / 1000;
+               if (remaining <= 0)
+               {       /* poll() would interpret negative values as no timeout */
+                       return OUT_OF_RES;
+               }
+               res = poll(&pfd, 1, remaining);
                if (res < 0)
                {
                        DBG1(DBG_CFG, "waiting for RADIUS message failed: %s",