mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-17 12:18:08 +00:00
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:
@ -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. */
|
||||
|
||||
|
Reference in New Issue
Block a user