From: W.C.A. Wijngaards Date: Wed, 30 Nov 2022 09:18:27 +0000 (+0100) Subject: - Fix #782: Segmentation fault in stats.c:404. X-Git-Tag: release-1.17.1rc1~13^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=effbf99281874d60262e07b5c938b1e01b7526cb;p=thirdparty%2Funbound.git - Fix #782: Segmentation fault in stats.c:404. --- diff --git a/doc/Changelog b/doc/Changelog index 1b1190673..8f561a5a5 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -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. diff --git a/util/tube.c b/util/tube.c index f08b05bba..7d98b93c3 100644 --- a/util/tube.c +++ b/util/tube.c @@ -45,6 +45,9 @@ #include "util/netevent.h" #include "util/fptr_wlist.h" #include "util/ub_event.h" +#ifdef HAVE_POLL_H +#include +#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)