From cd377f3d99b142da0520b812998acac0dd415224 Mon Sep 17 00:00:00 2001 From: Rishi Ranjan <43873720+rish9101@users.noreply.github.com> Date: Tue, 10 Mar 2020 17:37:29 +0530 Subject: Replace alarms with select and threads (#243) * Use select to monitor forkserver for timeouts instead of alarm * Remove redundent conditons in select monitoring of fdsin forkserver and cmplog * Replace SIGALARM with POSIX timers in afl-fuzz-run * Make changes to Makefile to use POSIX timers * Resolve Merge Conflicts and rename variables accordingly * Change forkserver and cmplog to handle exec_tmout = 0 * Handle timeout function bug rectify * Add error handling to afl-fuzz run timers * Add timer_delete to afl-fuzz-run * Remove memory leaks --- src/afl-fuzz-cmplog.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'src/afl-fuzz-cmplog.c') diff --git a/src/afl-fuzz-cmplog.c b/src/afl-fuzz-cmplog.c index c32ed546..6e9f603b 100644 --- a/src/afl-fuzz-cmplog.c +++ b/src/afl-fuzz-cmplog.c @@ -24,15 +24,17 @@ */ +#include + #include "afl-fuzz.h" #include "cmplog.h" void init_cmplog_forkserver(afl_state_t *afl) { - static struct itimerval it; - int st_pipe[2], ctl_pipe[2]; - int status; - s32 rlen; + static struct timeval timeout; + int st_pipe[2], ctl_pipe[2]; + int status; + s32 rlen; ACTF("Spinning up the cmplog fork server..."); @@ -182,20 +184,28 @@ void init_cmplog_forkserver(afl_state_t *afl) { if (afl->fsrv.exec_tmout) { - it.it_value.tv_sec = ((afl->fsrv.exec_tmout * FORK_WAIT_MULT) / 1000); - it.it_value.tv_usec = - ((afl->fsrv.exec_tmout * FORK_WAIT_MULT) % 1000) * 1000; + fd_set readfds; + FD_ZERO(&readfds); + FD_SET(afl->cmplog_fsrv_st_fd, &readfds); + timeout.tv_sec = ((afl->fsrv.exec_tmout * FORK_WAIT_MULT) / 1000); + timeout.tv_usec = ((afl->fsrv.exec_tmout * FORK_WAIT_MULT) % 1000) * 1000; - } + int sret = select(afl->cmplog_fsrv_st_fd + 1, &readfds, NULL, NULL, &timeout); - setitimer(ITIMER_REAL, &it, NULL); + if (sret == 0) { - rlen = read(afl->cmplog_fsrv_st_fd, &status, 4); + kill(afl->cmplog_fsrv_pid, SIGKILL); - it.it_value.tv_sec = 0; - it.it_value.tv_usec = 0; + } else { - setitimer(ITIMER_REAL, &it, NULL); + rlen = read(afl->cmplog_fsrv_st_fd, &status, 4); + + } + } else { + + rlen = read(afl->cmplog_fsrv_st_fd, &status, 4); + + } /* If we have a four-byte "hello" message from the server, we're all set. Otherwise, try to figure out what went wrong. */ -- cgit 1.4.1