From a6930f5c36f8511faa31c9be530f987a37eb2b49 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Thu, 30 May 2019 10:19:52 -0500 Subject: [PATCH] linux_tcp/poll: fix undefined behavior in select The select(2) system call on Linux now includes the restrict qualifier on the fd_set pointers passed in, causing a diagnostic in gcc9 for the call blocking for both read and write. Pass a pointer to a temporary copy of the set when two references are required. Signed-off-by: Peter A. Bigot --- src/linux_tcp/poll.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/linux_tcp/poll.h b/src/linux_tcp/poll.h index fa2be30..6839c29 100644 --- a/src/linux_tcp/poll.h +++ b/src/linux_tcp/poll.h @@ -106,8 +106,11 @@ public: */ bool active(bool block) { + // accommodate restrict qualifier on fd_set params + fd_set set2 = _set; + // wait for the socket - if (block) return select(_socket + 1, &_set, &_set, nullptr, nullptr) > 0; + if (block) return select(_socket + 1, &_set, &set2, nullptr, nullptr) > 0; // we do not want to block, so we use a small timeout struct timeval timeout; @@ -116,7 +119,7 @@ public: timeout.tv_sec = timeout.tv_usec = 0; // no timeout at all - return select(_socket + 1, &_set, &_set, nullptr, &timeout) > 0; + return select(_socket + 1, &_set, &set2, nullptr, &timeout) > 0; } }; @@ -124,4 +127,3 @@ public: * End of namespace */ } -