resize fix + code format

This commit is contained in:
Dominik Maier
2020-04-10 17:47:22 +02:00
parent 6aa6af04ac
commit f0f83bab52
10 changed files with 32 additions and 24 deletions

View File

@ -99,9 +99,11 @@ u8 *u_stringify_time_diff(u8 *buf, u64 cur_ms, u64 event_ms);
/* Wrapper for select() and read(), reading exactly len bytes.
Returns the time passed to read.
stop_soon should point to a variable indicating ctrl+c was pressed.
If the wait times out, returns timeout_ms + 1;
Returns 0 if an error occurred (fd closed, signal, ...); */
u32 read_timed(s32 fd, void *buf, size_t len, u32 timeout_ms);
u32 read_timed(s32 fd, void *buf, size_t len, u32 timeout_ms,
volatile u8 *stop_soon_p);
#endif

View File

@ -67,7 +67,8 @@ typedef struct afl_forkserver {
} afl_forkserver_t;
void afl_fsrv_init(afl_forkserver_t *fsrv);
void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv);
void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
volatile u8 *stop_soon_p);
void afl_fsrv_deinit(afl_forkserver_t *fsrv);
void afl_fsrv_killall();

View File

@ -40,6 +40,7 @@
u8 be_quiet = 0;
u8 *doc_path = "";
u8 last_intr = 0;
char *afl_environment_variables[] = {
@ -754,7 +755,8 @@ u8 *u_stringify_time_diff(u8 *buf, u64 cur_ms, u64 event_ms) {
Returns the time passed to read.
If the wait times out, returns timeout_ms + 1;
Returns 0 if an error occurred (fd closed, signal, ...); */
u32 read_timed(s32 fd, void *buf, size_t len, u32 timeout_ms) {
u32 read_timed(s32 fd, void *buf, size_t len, u32 timeout_ms,
volatile u8 *stop_soon_p) {
struct timeval timeout;
fd_set readfds;
@ -779,8 +781,8 @@ u32 read_timed(s32 fd, void *buf, size_t len, u32 timeout_ms) {
} else if (sret < 0) {
// perror("sret malloc");
// TODO: catch other (errno == EINTR) than ctrl+c?
/* Retry select for all signals other than than ctrl+c */
if (errno == EINTR && !*stop_soon_p) { continue; }
return 0;
}

View File

@ -160,7 +160,8 @@ static void afl_fauxsrv_execv(afl_forkserver_t *fsrv, char **argv) {
cloning a stopped child. So, we just execute once, and then send commands
through a pipe. The other part of this logic is in afl-as.h / llvm_mode */
void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv) {
void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
volatile u8 *stop_soon_p) {
int st_pipe[2], ctl_pipe[2];
int status;
@ -317,7 +318,7 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv) {
rlen = 4;
u32 time = read_timed(fsrv->fsrv_st_fd, &status, rlen,
fsrv->exec_tmout * FORK_WAIT_MULT);
fsrv->exec_tmout * FORK_WAIT_MULT, stop_soon_p);
if (time > fsrv->exec_tmout * FORK_WAIT_MULT) {

View File

@ -187,7 +187,8 @@ void init_cmplog_forkserver(afl_state_t *afl) {
rlen = 4;
u32 timeout_ms = afl->fsrv.exec_tmout * FORK_WAIT_MULT;
/* Reuse readfds as exceptfds to see when the child closed the pipe */
u32 exec_ms = read_timed(afl->cmplog_fsrv_st_fd, &status, rlen, timeout_ms);
u32 exec_ms = read_timed(afl->cmplog_fsrv_st_fd, &status, rlen, timeout_ms,
&afl->stop_soon);
if (!exec_ms) {
@ -416,7 +417,8 @@ u8 run_cmplog_target(afl_state_t *afl, u32 timeout) {
/* Configure timeout, as requested by user, then wait for child to terminate.
*/
exec_ms = read_timed(afl->cmplog_fsrv_st_fd, &status, 4, timeout);
exec_ms =
read_timed(afl->cmplog_fsrv_st_fd, &status, 4, timeout, &afl->stop_soon);
if (exec_ms > timeout) {

View File

@ -134,14 +134,12 @@ void bind_to_free_cpu(afl_state_t *afl) {
for (i = 0; i < proccount; i++) {
#if defined(__FreeBSD__)
if (!strcmp(procs[i].ki_comm, "idle"))
continue;
if (!strcmp(procs[i].ki_comm, "idle")) continue;
// fix when ki_oncpu = -1
int oncpu;
oncpu = procs[i].ki_oncpu;
if (oncpu == -1)
oncpu = procs[i].ki_lastcpu;
if (oncpu == -1) oncpu = procs[i].ki_lastcpu;
if (oncpu != -1 && oncpu < sizeof(cpu_used) && procs[i].ki_pctcpu > 60)
cpu_used[oncpu] = 1;

View File

@ -67,7 +67,8 @@ u8 run_target(afl_state_t *afl, u32 timeout) {
if (afl->fsrv.child_pid <= 0) FATAL("Fork server is misbehaving (OOM?)");
exec_ms = read_timed(afl->fsrv.fsrv_st_fd, &status, 4, timeout);
exec_ms =
read_timed(afl->fsrv.fsrv_st_fd, &status, 4, timeout, &afl->stop_soon);
if (exec_ms > timeout) {
@ -308,7 +309,8 @@ u8 calibrate_case(afl_state_t *afl, struct queue_entry *q, u8 *use_mem,
/* Make sure the forkserver is up before we do anything, and let's not
count its spin-up time toward binary calibration. */
if (!afl->fsrv.fsrv_pid) afl_fsrv_start(&afl->fsrv, afl->argv);
if (!afl->fsrv.fsrv_pid)
afl_fsrv_start(&afl->fsrv, afl->argv, &afl->stop_soon);
if (afl->dumb_mode != 1 && !afl->no_forkserver && !afl->cmplog_fsrv_pid &&
afl->shm.cmplog_mode)
init_cmplog_forkserver(afl);

View File

@ -951,7 +951,7 @@ int main(int argc, char **argv_orig, char **envp) {
}
afl_fsrv_start(fsrv, use_argv);
afl_fsrv_start(fsrv, use_argv, &stop_soon);
while (done == 0 && (dir_ent = readdir(dir_in))) {

View File

@ -1133,7 +1133,7 @@ int main(int argc, char **argv_orig, char **envp) {
read_initial_file();
afl_fsrv_start(fsrv, use_argv);
afl_fsrv_start(fsrv, use_argv, &stop_soon);
ACTF("Performing dry run (mem limit = %llu MB, timeout = %u ms%s)...",
fsrv->mem_limit, fsrv->exec_tmout, edges_only ? ", edges only" : "");