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
This commit is contained in:
Rishi Ranjan
2020-03-10 17:37:29 +05:30
committed by GitHub
parent 0def6e3471
commit cd377f3d99
4 changed files with 138 additions and 48 deletions

View File

@ -41,6 +41,7 @@
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <sys/select.h>
/* Describe integer as memory size. */
@ -168,10 +169,10 @@ void afl_fsrv_init(afl_forkserver_t *fsrv) {
void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv) {
static struct itimerval it;
int st_pipe[2], ctl_pipe[2];
int status;
s32 rlen;
struct timeval timeout;
int st_pipe[2], ctl_pipe[2];
int status;
s32 rlen;
if (!getenv("AFL_QUIET")) ACTF("Spinning up the fork server...");
@ -311,20 +312,31 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv) {
if (fsrv->exec_tmout) {
it.it_value.tv_sec = ((fsrv->exec_tmout * FORK_WAIT_MULT) / 1000);
it.it_value.tv_usec = ((fsrv->exec_tmout * FORK_WAIT_MULT) % 1000) * 1000;
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(fsrv->fsrv_st_fd, &readfds);
timeout.tv_sec = ((fsrv->exec_tmout * FORK_WAIT_MULT) / 1000);
timeout.tv_usec = ((fsrv->exec_tmout * FORK_WAIT_MULT) % 1000) * 1000;
int sret = select(fsrv->fsrv_st_fd + 1, &readfds, NULL, NULL, &timeout);
if (sret == 0) {
fsrv->child_timed_out = 1;
kill(fsrv->child_pid, SIGKILL);
} else {
rlen = read(fsrv->fsrv_st_fd, &status, 4);
}
} else {
rlen = read(fsrv->fsrv_st_fd, &status, 4);
}
setitimer(ITIMER_REAL, &it, NULL);
rlen = read(fsrv->fsrv_st_fd, &status, 4);
it.it_value.tv_sec = 0;
it.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &it, NULL);
/* If we have a four-byte "hello" message from the server, we're all set.
Otherwise, try to figure out what went wrong. */