From: Tobias Brunner Date: Wed, 17 Jun 2026 10:03:23 +0000 (+0200) Subject: radius-socket: Fix timeout handling when waiting for responses X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6dfebcede5aaa02b58da9643cf0ea3831ba49df7;p=thirdparty%2Fstrongswan.git radius-socket: Fix timeout handling when waiting for responses In case messages with unexpected IDs are received, the previous code would always wait for the full timeout again. --- diff --git a/src/libradius/radius_socket.c b/src/libradius/radius_socket.c index 4b93fbda18..a1ee001676 100644 --- a/src/libradius/radius_socket.c +++ b/src/libradius/radius_socket.c @@ -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",