diff options
author | Robert Swiecki <robert@swiecki.net> | 2018-08-19 04:12:35 +0200 |
---|---|---|
committer | Robert Swiecki <robert@swiecki.net> | 2018-08-19 04:12:35 +0200 |
commit | 518d4d2cc0ad24deaadc14e5fccde6361c0a2db4 (patch) | |
tree | 9a9d8d917bee5e59268a5f0258c71d7d59242d65 /netbsd | |
parent | f5546d32915c14f71a9dce9e3e658e760e41bafc (diff) | |
download | honggfuzz-518d4d2cc0ad24deaadc14e5fccde6361c0a2db4.tar.gz |
make indent depend
Diffstat (limited to 'netbsd')
-rw-r--r-- | netbsd/arch.c | 7 | ||||
-rw-r--r-- | netbsd/trace.c | 173 |
2 files changed, 95 insertions, 85 deletions
diff --git a/netbsd/arch.c b/netbsd/arch.c index 81d41b0f..33d8bebf 100644 --- a/netbsd/arch.c +++ b/netbsd/arch.c @@ -24,7 +24,6 @@ #include "arch.h" #include <sys/param.h> -#include <sys/types.h> #include <sys/ptrace.h> #include <sys/syscall.h> #include <sys/time.h> @@ -38,6 +37,7 @@ #include <fcntl.h> #include <inttypes.h> #include <locale.h> +#include <poll.h> #include <setjmp.h> #include <signal.h> #include <stdio.h> @@ -45,7 +45,6 @@ #include <string.h> #include <time.h> #include <unistd.h> -#include <poll.h> #include "fuzz.h" #include "libhfcommon/common.h" @@ -58,7 +57,7 @@ #include "sanitizers.h" #include "subproc.h" -extern char **environ; +extern char** environ; static inline bool arch_shouldAttach(run_t* run) { if (run->global->exe.persistent && run->netbsd.attachedPid == run->pid) { @@ -147,7 +146,7 @@ static bool arch_attachToNewPid(run_t* run, pid_t pid) { if (!arch_traceAttach(run, pid)) { LOG_W("arch_traceAttach(pid=%d) failed", pid); kill(pid, SIGKILL); - /* TODO: missing wait(2)? */ + /* TODO: missing wait(2)? */ return false; } diff --git a/netbsd/trace.c b/netbsd/trace.c index 3fba2122..c9858ed9 100644 --- a/netbsd/trace.c +++ b/netbsd/trace.c @@ -24,7 +24,6 @@ #include "netbsd/trace.h" #include <sys/param.h> -#include <sys/types.h> #include <sys/ptrace.h> #include <sys/resource.h> #include <sys/stat.h> @@ -117,7 +116,6 @@ static struct { #define SI_FROMUSER(siptr) ((siptr)->si_code == SI_USER) #endif /* SI_FROMUSER */ - static __thread char arch_signame[32]; static const char* arch_sigName(int signo) { snprintf(arch_signame, sizeof(arch_signame), "SIG%s", signalname(signo)); @@ -133,13 +131,14 @@ static size_t arch_getProcMem(pid_t pid, uint8_t* buf, size_t len, register_t pc io.piod_len = len; do { - io.piod_offs = (void *)(pc + bytes_read); + io.piod_offs = (void*)(pc + bytes_read); io.piod_addr = buf + bytes_read; if (ptrace(PT_IO, pid, &io, 0) == -1) { - PLOG_W("Couldn't read process memory on pid %d, " - "piod_op: %d offs: %p addr: %p piod_len: %zu", - pid, io.piod_op, io.piod_offs, io.piod_addr, io.piod_len); + PLOG_W( + "Couldn't read process memory on pid %d, " + "piod_op: %d offs: %p addr: %p piod_len: %zu", + pid, io.piod_op, io.piod_offs, io.piod_addr, io.piod_len); break; } @@ -150,7 +149,8 @@ static size_t arch_getProcMem(pid_t pid, uint8_t* buf, size_t len, register_t pc return bytes_read; } -static size_t arch_getPC(pid_t pid, lwpid_t lwp, register_t* pc, register_t* status_reg HF_ATTR_UNUSED) { +static size_t arch_getPC( + pid_t pid, lwpid_t lwp, register_t* pc, register_t* status_reg HF_ATTR_UNUSED) { struct reg r; if (ptrace(PT_GETREGS, pid, &r, lwp) != 0) { @@ -163,7 +163,7 @@ static size_t arch_getPC(pid_t pid, lwpid_t lwp, register_t* pc, register_t* sta #elif defined(__x86_64__) *status_reg = r.regs[_REG_RFLAGS]; #else -# error unsupported CPU architecture +#error unsupported CPU architecture #endif return sizeof(r); @@ -201,7 +201,7 @@ static void arch_getInstrStr(pid_t pid, lwpid_t lwp, register_t* pc, char* instr arch = CS_ARCH_X86; mode = CS_MODE_64; #else -# error Unsupported CPU architecture +#error Unsupported CPU architecture #endif csh handle; @@ -226,7 +226,8 @@ static void arch_getInstrStr(pid_t pid, lwpid_t lwp, register_t* pc, char* instr cs_close(&handle); for (int x = 0; instr[x] && x < _HF_INSTR_SZ; x++) { - if (instr[x] == '/' || instr[x] == '\\' || isspace((unsigned char)instr[x]) || !isprint((unsigned char)instr[x])) { + if (instr[x] == '/' || instr[x] == '\\' || isspace((unsigned char)instr[x]) || + !isprint((unsigned char)instr[x])) { instr[x] = '_'; } } @@ -234,7 +235,8 @@ static void arch_getInstrStr(pid_t pid, lwpid_t lwp, register_t* pc, char* instr return; } -static void arch_hashCallstack(run_t* run, funcs_t* funcs HF_ATTR_UNUSED, size_t funcCnt, bool enableMasking) { +static void arch_hashCallstack( + run_t* run, funcs_t* funcs HF_ATTR_UNUSED, size_t funcCnt, bool enableMasking) { uint64_t hash = 0; for (size_t i = 0; i < funcCnt && i < run->global->netbsd.numMajorFrames; i++) { /* @@ -342,12 +344,15 @@ static void arch_traceSaveData(run_t* run, pid_t pid) { arch_getInstrStr(pid, info.psi_lwpid, &pc, instr); - LOG_D("Pid: %d, signo: %d, errno: %d, code: %d, addr: %p, pc: %" PRIxREGISTER ", instr: '%s'", pid, - info.psi_siginfo.si_signo, info.psi_siginfo.si_errno, info.psi_siginfo.si_code, info.psi_siginfo.si_addr, pc, instr); + LOG_D("Pid: %d, signo: %d, errno: %d, code: %d, addr: %p, pc: %" PRIxREGISTER ", instr: '%s'", + pid, info.psi_siginfo.si_signo, info.psi_siginfo.si_errno, info.psi_siginfo.si_code, + info.psi_siginfo.si_addr, pc, instr); - if (!SI_FROMUSER(&info.psi_siginfo) && pc && info.psi_siginfo.si_addr < run->global->netbsd.ignoreAddr) { + if (!SI_FROMUSER(&info.psi_siginfo) && pc && + info.psi_siginfo.si_addr < run->global->netbsd.ignoreAddr) { LOG_I("Input is interesting (%s), but the si.si_addr is %p (below %p), skipping", - arch_sigName(info.psi_siginfo.si_signo), info.psi_siginfo.si_addr, run->global->netbsd.ignoreAddr); + arch_sigName(info.psi_siginfo.si_signo), info.psi_siginfo.si_addr, + run->global->netbsd.ignoreAddr); return; } @@ -477,15 +482,15 @@ static void arch_traceSaveData(run_t* run, pid_t pid) { } else if (saveUnique) { snprintf(run->crashFileName, sizeof(run->crashFileName), "%s/%s.PC.%" PRIxREGISTER ".STACK.%" PRIx64 ".CODE.%d.ADDR.%p.INSTR.%s.%s", - run->global->io.crashDir, arch_sigName(info.psi_siginfo.si_signo), pc, run->backtrace, info.psi_siginfo.si_code, - sig_addr, instr, run->global->io.fileExtn); + run->global->io.crashDir, arch_sigName(info.psi_siginfo.si_signo), pc, run->backtrace, + info.psi_siginfo.si_code, sig_addr, instr, run->global->io.fileExtn); } else { char localtmstr[PATH_MAX]; util_getLocalTime("%F.%H:%M:%S", localtmstr, sizeof(localtmstr), time(NULL)); snprintf(run->crashFileName, sizeof(run->crashFileName), "%s/%s.PC.%" PRIxREGISTER ".STACK.%" PRIx64 ".CODE.%d.ADDR.%p.INSTR.%s.%s.%d.%s", - run->global->io.crashDir, arch_sigName(info.psi_siginfo.si_signo), pc, run->backtrace, info.psi_siginfo.si_code, - sig_addr, instr, localtmstr, pid, run->global->io.fileExtn); + run->global->io.crashDir, arch_sigName(info.psi_siginfo.si_signo), pc, run->backtrace, + info.psi_siginfo.si_code, sig_addr, instr, localtmstr, pid, run->global->io.fileExtn); } /* Target crashed (no duplicate detection yet) */ @@ -836,67 +841,73 @@ static void arch_traceEvent(run_t* run HF_ATTR_UNUSED, pid_t pid) { ptrace(PT_GET_SIGINFO, pid, &info, sizeof(info)); switch (info.psi_siginfo.si_code) { - case TRAP_BRKPT: - /* Software breakpoint trap, pass it over to tracee */ - sig = SIGTRAP; - LOG_D("PID: %d breakpoint software trap (TRAP_BRKPT)", pid); - break; - case TRAP_TRACE: - /* Single step unused */ - LOG_E("PID: %d unexpected single step trace trap (TRAP_TRACE)", pid); - break; - case TRAP_EXEC: - /* exec(3) trap, ignore */ - LOG_D("PID: %d breakpoint software trap (TRAP_EXEC)", pid); - break; - case TRAP_CHLD: - case TRAP_LWP: - /* Child/LWP trap, ignore */ - if (ptrace(PT_GET_PROCESS_STATE, pid, &state, sizeof(state)) != -1) { - switch (state.pe_report_event) { - case PTRACE_FORK: - case PTRACE_VFORK: - LOG_D("PID: %d child trap (TRAP_CHLD) : fork (%s)", pid, state.pe_report_event == PTRACE_FORK ? "PTRACE_FORK" : "PTRACE_VFORK"); - /* Do not support fuzzing (v)forkees */ - int status; - waitpid(state.pe_other_pid, &status, 0); - ptrace(PT_DETACH, state.pe_other_pid, (void *)1, 0); - break; - case PTRACE_VFORK_DONE: - LOG_D("PID: %d child trap (TRAP_CHLD) : vfork (PTRACE_VFORK_DONE)", pid); - break; - case PTRACE_LWP_CREATE: - LOG_E("PID: %d unexpected lwp trap (TRAP_LWP) : create (PTRACE_LWP_CREATE)", pid); - break; - case PTRACE_LWP_EXIT: - LOG_E("PID: %d unexpected lwp trap (TRAP_LWP) : exit (PTRACE_LWP_EXIT)", pid); - break; - default: - LOG_D("PID: %d unknown child/lwp trap (TRAP_LWP/TRAP_CHLD) : unknown pe_report_event=%d", pid, state.pe_report_event); - break; + case TRAP_BRKPT: + /* Software breakpoint trap, pass it over to tracee */ + sig = SIGTRAP; + LOG_D("PID: %d breakpoint software trap (TRAP_BRKPT)", pid); + break; + case TRAP_TRACE: + /* Single step unused */ + LOG_E("PID: %d unexpected single step trace trap (TRAP_TRACE)", pid); + break; + case TRAP_EXEC: + /* exec(3) trap, ignore */ + LOG_D("PID: %d breakpoint software trap (TRAP_EXEC)", pid); + break; + case TRAP_CHLD: + case TRAP_LWP: + /* Child/LWP trap, ignore */ + if (ptrace(PT_GET_PROCESS_STATE, pid, &state, sizeof(state)) != -1) { + switch (state.pe_report_event) { + case PTRACE_FORK: + case PTRACE_VFORK: + LOG_D("PID: %d child trap (TRAP_CHLD) : fork (%s)", pid, + state.pe_report_event == PTRACE_FORK ? "PTRACE_FORK" : "PTRACE_VFORK"); + /* Do not support fuzzing (v)forkees */ + int status; + waitpid(state.pe_other_pid, &status, 0); + ptrace(PT_DETACH, state.pe_other_pid, (void*)1, 0); + break; + case PTRACE_VFORK_DONE: + LOG_D("PID: %d child trap (TRAP_CHLD) : vfork (PTRACE_VFORK_DONE)", pid); + break; + case PTRACE_LWP_CREATE: + LOG_E("PID: %d unexpected lwp trap (TRAP_LWP) : create (PTRACE_LWP_CREATE)", + pid); + break; + case PTRACE_LWP_EXIT: + LOG_E( + "PID: %d unexpected lwp trap (TRAP_LWP) : exit (PTRACE_LWP_EXIT)", pid); + break; + default: + LOG_D( + "PID: %d unknown child/lwp trap (TRAP_LWP/TRAP_CHLD) : unknown " + "pe_report_event=%d", + pid, state.pe_report_event); + break; + } } - } - break; - case TRAP_DBREG: - /* Debug Register trap unused */ - LOG_E("PID: %d unexpected debug register trap (TRAP_DBREG)", pid); - break; - case TRAP_SCE: - /* Syscall Enter trap unused */ - LOG_E("PID: %d unexpected syscall enter trap (TRAP_SCE)", pid); - break; - case TRAP_SCX: - /* Syscall Exit trap unused */ - LOG_E("PID: %d unexpected syscall exit trap (TRAP_SCX)", pid); - break; - default: - /* Other trap, pass it over to tracee */ - sig = SIGTRAP; - LOG_D("PID: %d other trap si_code=%d", pid, info.psi_siginfo.si_code); - break; - } - - ptrace(PT_CONTINUE, pid, (void *)1, sig); + break; + case TRAP_DBREG: + /* Debug Register trap unused */ + LOG_E("PID: %d unexpected debug register trap (TRAP_DBREG)", pid); + break; + case TRAP_SCE: + /* Syscall Enter trap unused */ + LOG_E("PID: %d unexpected syscall enter trap (TRAP_SCE)", pid); + break; + case TRAP_SCX: + /* Syscall Exit trap unused */ + LOG_E("PID: %d unexpected syscall exit trap (TRAP_SCX)", pid); + break; + default: + /* Other trap, pass it over to tracee */ + sig = SIGTRAP; + LOG_D("PID: %d other trap si_code=%d", pid, info.psi_siginfo.si_code); + break; + } + + ptrace(PT_CONTINUE, pid, (void*)1, sig); } void arch_traceAnalyze(run_t* run, int status, pid_t pid) { @@ -924,7 +935,7 @@ void arch_traceAnalyze(run_t* run, int status, pid_t pid) { } /* Do not deliver SIGSTOP */ int sig = (WSTOPSIG(status) != SIGSTOP) ? WSTOPSIG(status) : 0; - ptrace(PT_CONTINUE, pid, (void *)1, sig); + ptrace(PT_CONTINUE, pid, (void*)1, sig); return; } @@ -995,7 +1006,7 @@ bool arch_traceAttach(run_t* run, pid_t pid) { LOG_D("Attached to PID: %d", pid); - if (ptrace(PT_CONTINUE, pid, (void *)1, 0) == -1) { + if (ptrace(PT_CONTINUE, pid, (void*)1, 0) == -1) { PLOG_W("Couldn't ptrace(PT_CONTINUE) to pid: %d", pid); return false; } |