Skip to content

Commit a5ae138

Browse files
Merge pull request #2481 from kcwu/select-poll
replace select() by poll()
2 parents 9d6e45f + 63cdbff commit a5ae138

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

src/afl-forkserver.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
#include <signal.h>
4747
#include <fcntl.h>
4848
#include <limits.h>
49+
#include <poll.h>
4950
#include <sys/time.h>
5051
#include <sys/wait.h>
5152
#include <sys/resource.h>
52-
#include <sys/select.h>
5353
#include <sys/stat.h>
5454
#include <grp.h>
5555

@@ -400,31 +400,28 @@ void afl_fsrv_setup_preload(afl_forkserver_t *fsrv, char *argv0) {
400400

401401
}
402402

403-
/* Wrapper for select() and read(), reading a 32 bit var.
403+
/* Wrapper for poll() and read(), reading a 32 bit var.
404404
Returns the time passed to read.
405405
If the wait times out, returns timeout_ms + 1;
406406
Returns 0 if an error occurred (fd closed, signal, ...); */
407407
static u32 __attribute__((hot)) read_s32_timed(s32 fd, s32 *buf, u32 timeout_ms,
408408
volatile u8 *stop_soon_p) {
409409

410-
fd_set readfds;
411-
FD_ZERO(&readfds);
412-
FD_SET(fd, &readfds);
413-
struct timeval timeout;
414-
int sret;
415-
ssize_t len_read;
410+
int pret;
411+
ssize_t len_read;
412+
struct pollfd fds[1];
413+
int nfds = 1;
416414

417-
timeout.tv_sec = (timeout_ms / 1000);
418-
timeout.tv_usec = (timeout_ms % 1000) * 1000;
419-
#if !defined(__linux__)
420415
u32 read_start = get_cur_time_us();
421-
#endif
422416

423-
/* set exceptfds as well to return when a child exited/closed the pipe. */
424-
restart_select:
425-
sret = select(fd + 1, &readfds, NULL, NULL, &timeout);
417+
memset(&fds, 0, sizeof(fds));
418+
fds[0].fd = fd;
419+
fds[0].events = POLLIN;
426420

427-
if (likely(sret > 0)) {
421+
/* set exceptfds as well to return when a child exited/closed the pipe. */
422+
restart_poll:
423+
pret = poll(fds, nfds, timeout_ms);
424+
if (likely(pret > 0)) {
428425

429426
restart_read:
430427
if (*stop_soon_p) {
@@ -438,13 +435,7 @@ static u32 __attribute__((hot)) read_s32_timed(s32 fd, s32 *buf, u32 timeout_ms,
438435

439436
if (likely(len_read == 4)) { // for speed we put this first
440437

441-
#if defined(__linux__)
442-
u32 exec_ms = MIN(
443-
timeout_ms,
444-
((u64)timeout_ms - (timeout.tv_sec * 1000 + timeout.tv_usec / 1000)));
445-
#else
446438
u32 exec_ms = MIN(timeout_ms, (get_cur_time_us() - read_start) / 1000);
447-
#endif
448439

449440
// ensure to report 1 ms has passed (0 is an error)
450441
return exec_ms > 0 ? exec_ms : 1;
@@ -459,14 +450,14 @@ static u32 __attribute__((hot)) read_s32_timed(s32 fd, s32 *buf, u32 timeout_ms,
459450

460451
}
461452

462-
} else if (unlikely(!sret)) {
453+
} else if (unlikely(!pret)) {
463454

464455
*buf = -1;
465456
return timeout_ms + 1;
466457

467-
} else if (unlikely(sret < 0)) {
458+
} else if (unlikely(pret < 0)) {
468459

469-
if (likely(errno == EINTR)) goto restart_select;
460+
if (likely(errno == EINTR)) goto restart_poll;
470461

471462
*buf = -1;
472463
return 0;

src/afl-fuzz-cmplog.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
2525
*/
2626

27-
#include <sys/select.h>
28-
2927
#include "afl-fuzz.h"
3028
#include "cmplog.h"
3129

src/afl-fuzz-sanfuzz.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
/* This file roughly follows afl-fuzz-asanfuzz */
2828

29-
#include <sys/select.h>
30-
3129
#include "afl-fuzz.h"
3230

3331
void sanfuzz_exec_child(afl_forkserver_t *fsrv, char **argv) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy