]> git.sesse.net Git - vlc/commitdiff
Use poll() instead of select() to fix an unlikely overflow in FD_SET
authorRémi Denis-Courmont <rem@videolan.org>
Fri, 18 Jan 2008 17:25:22 +0000 (17:25 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Fri, 18 Jan 2008 17:25:22 +0000 (17:25 +0000)
modules/gui/skins2/x11/x11_timer.cpp

index fb83bd403fad144a9769f9802b16563d41af7157..bfc9e0d8525af9dca622d21ef48c5d8ed09c0777 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <poll.h>
 
 #include "x11_timer.hpp"
 #include "x11_factory.hpp"
@@ -146,20 +147,14 @@ void X11TimerLoop::waitNextTimer()
 
 bool X11TimerLoop::sleep( int delay )
 {
-    // Timeout delay
-    struct timeval tv;
-    tv.tv_sec = delay / 1000;
-    tv.tv_usec = 1000 * (delay % 1000);
-
-    // FD set for select()
-    fd_set rfds;
-    FD_ZERO( &rfds );
-    FD_SET( m_connectionNumber, &rfds );
+    struct pollfd ufd = {
+        .fd = m_connectionNumber,
+        .events = POLLIN,
+    };
 
     // Wait for an X11 event, or timeout
-    int num = select( m_connectionNumber + 1, &rfds, NULL, NULL, &tv );
-
-    return ( num > 0 );
+    // TODO: use VLC object waitpipe?
+    return poll( &ufd, 1, delay ) > 0;
 }