Skip to content

Commit effbf99

Browse files
committed
- Fix NLnetLabs#782: Segmentation fault in stats.c:404.
1 parent 81861ae commit effbf99

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

doc/Changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
30 November 2022: Wouter
2+
- Fix #782: Segmentation fault in stats.c:404.
3+
14
28 November 2022: Wouter
25
- Fix for the ignore of tcp events for closed comm points, preserve
36
the use after free protection features.

util/tube.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#include "util/netevent.h"
4646
#include "util/fptr_wlist.h"
4747
#include "util/ub_event.h"
48+
#ifdef HAVE_POLL_H
49+
#include <poll.h>
50+
#endif
4851

4952
#ifndef USE_WINSOCK
5053
/* on unix */
@@ -396,20 +399,28 @@ int tube_read_msg(struct tube* tube, uint8_t** buf, uint32_t* len,
396399
return 1;
397400
}
398401

399-
/** perform a select() on the fd */
402+
/** perform poll() on the fd */
400403
static int
401404
pollit(int fd, struct timeval* t)
402405
{
403-
fd_set r;
406+
struct pollfd fds;
407+
int pret;
408+
int msec = -1;
409+
memset(&fds, 0, sizeof(fds));
410+
fds.fd = fd;
411+
fds.events = POLLIN | POLLERR | POLLHUP;
404412
#ifndef S_SPLINT_S
405-
FD_ZERO(&r);
406-
FD_SET(FD_SET_T fd, &r);
413+
if(t)
414+
msec = t->tv_sec*1000 + t->tv_usec/1000;
407415
#endif
408-
if(select(fd+1, &r, NULL, NULL, t) == -1) {
416+
417+
pret = poll(&fds, 1, msec);
418+
419+
if(pret == -1)
409420
return 0;
410-
}
411-
errno = 0;
412-
return (int)(FD_ISSET(fd, &r));
421+
if(pret != 0)
422+
return 1;
423+
return 0;
413424
}
414425

415426
int tube_poll(struct tube* tube)
@@ -426,24 +437,27 @@ int tube_wait(struct tube* tube)
426437

427438
int tube_wait_timeout(struct tube* tube, int msec)
428439
{
429-
struct timeval t;
430-
int fd = tube->sr;
431-
fd_set r;
432-
t.tv_sec = msec/1000;
433-
t.tv_usec = (msec%1000)*1000;
434-
#ifndef S_SPLINT_S
435-
FD_ZERO(&r);
436-
FD_SET(FD_SET_T fd, &r);
437-
#endif
440+
int ret = 0;
441+
438442
while(1) {
439-
if(select(fd+1, &r, NULL, NULL, &t) == -1) {
443+
struct pollfd fds;
444+
memset(&fds, 0, sizeof(fds));
445+
446+
fds.fd = tube->sr;
447+
fds.events = POLLIN | POLLERR | POLLHUP;
448+
ret = poll(&fds, 1, msec);
449+
450+
if(ret == -1) {
440451
if(errno == EAGAIN || errno == EINTR)
441452
continue;
442453
return -1;
443454
}
444455
break;
445456
}
446-
return (int)(FD_ISSET(fd, &r));
457+
458+
if(ret != 0)
459+
return 1;
460+
return 0;
447461
}
448462

449463
int tube_read_fd(struct tube* tube)

0 commit comments

Comments
 (0)