]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix #782: Segmentation fault in stats.c:404.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 30 Nov 2022 09:18:27 +0000 (10:18 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 30 Nov 2022 09:18:27 +0000 (10:18 +0100)
doc/Changelog
util/tube.c

index 1b1190673a2ff4cb76b89c946851e12da505e792..8f561a5a5c218a69af28bb85b39b200a0b47b40e 100644 (file)
@@ -1,3 +1,6 @@
+30 November 2022: Wouter
+       - Fix #782: Segmentation fault in stats.c:404.
+
 28 November 2022: Wouter
        - Fix for the ignore of tcp events for closed comm points, preserve
          the use after free protection features.
index f08b05bba848f8542b9eae374779520e5a7879ff..7d98b93c37517808e4e4ca62938f8d224206ce54 100644 (file)
@@ -45,6 +45,9 @@
 #include "util/netevent.h"
 #include "util/fptr_wlist.h"
 #include "util/ub_event.h"
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
 
 #ifndef USE_WINSOCK
 /* on unix */
@@ -396,20 +399,28 @@ int tube_read_msg(struct tube* tube, uint8_t** buf, uint32_t* len,
        return 1;
 }
 
-/** perform a select() on the fd */
+/** perform poll() on the fd */
 static int
 pollit(int fd, struct timeval* t)
 {
-       fd_set r;
+       struct pollfd fds;
+       int pret;
+       int msec = -1;
+       memset(&fds, 0, sizeof(fds));
+       fds.fd = fd;
+       fds.events = POLLIN | POLLERR | POLLHUP;
 #ifndef S_SPLINT_S
-       FD_ZERO(&r);
-       FD_SET(FD_SET_T fd, &r);
+       if(t)
+               msec = t->tv_sec*1000 + t->tv_usec/1000;
 #endif
-       if(select(fd+1, &r, NULL, NULL, t) == -1) {
+
+       pret = poll(&fds, 1, msec);
+
+       if(pret == -1)
                return 0;
-       }
-       errno = 0;
-       return (int)(FD_ISSET(fd, &r));
+       if(pret != 0)
+               return 1;
+       return 0;
 }
 
 int tube_poll(struct tube* tube)
@@ -426,24 +437,27 @@ int tube_wait(struct tube* tube)
 
 int tube_wait_timeout(struct tube* tube, int msec)
 {
-       struct timeval t;
-       int fd = tube->sr;
-       fd_set r;
-       t.tv_sec = msec/1000;
-       t.tv_usec = (msec%1000)*1000;
-#ifndef S_SPLINT_S
-       FD_ZERO(&r);
-       FD_SET(FD_SET_T fd, &r);
-#endif
+       int ret = 0;
+
        while(1) {
-               if(select(fd+1, &r, NULL, NULL, &t) == -1) {
+               struct pollfd fds;
+               memset(&fds, 0, sizeof(fds));
+
+               fds.fd = tube->sr;
+               fds.events = POLLIN | POLLERR | POLLHUP;
+               ret = poll(&fds, 1, msec);
+
+               if(ret == -1) {
                        if(errno == EAGAIN || errno == EINTR)
                                continue;
                        return -1;
                }
                break;
        }
-       return (int)(FD_ISSET(fd, &r));
+
+       if(ret != 0)
+               return 1;
+       return 0;
 }
 
 int tube_read_fd(struct tube* tube)