fix warning, code format

This commit is contained in:
van Hauser
2020-05-10 11:35:31 +02:00
parent 3beec8d4fa
commit 26f8708fed
42 changed files with 656 additions and 658 deletions

View File

@ -27,7 +27,7 @@
#define AFL_MAIN
#ifdef __ANDROID__
#include "android-ashmem.h"
# include "android-ashmem.h"
#endif
#include "config.h"
#include "types.h"

View File

@ -79,9 +79,9 @@ static u8 use_64bit = 1;
static u8 use_64bit = 0;
#ifdef __APPLE__
#error "Sorry, 32-bit Apple platforms are not supported."
#endif /* __APPLE__ */
# ifdef __APPLE__
# error "Sorry, 32-bit Apple platforms are not supported."
# endif /* __APPLE__ */
#endif /* ^WORD_SIZE_64 */

View File

@ -34,7 +34,7 @@
/* Detect @@ in args. */
#ifndef __glibc__
#include <unistd.h>
# include <unistd.h>
#endif
#include <limits.h>
#include <sys/types.h>

View File

@ -33,11 +33,11 @@
void bind_to_free_cpu(afl_state_t *afl) {
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
# if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
cpu_set_t c;
#elif defined(__NetBSD__)
# elif defined(__NetBSD__)
cpuset_t * c;
#endif
# endif
u8 cpu_used[4096] = {0};
u32 i;
@ -51,7 +51,7 @@ void bind_to_free_cpu(afl_state_t *afl) {
}
#if defined(__linux__)
# if defined(__linux__)
DIR * d;
struct dirent *de;
d = opendir("/proc");
@ -112,7 +112,7 @@ void bind_to_free_cpu(afl_state_t *afl) {
}
closedir(d);
#elif defined(__FreeBSD__) || defined(__DragonFly__)
# elif defined(__FreeBSD__) || defined(__DragonFly__)
struct kinfo_proc *procs;
size_t nprocs;
size_t proccount;
@ -133,7 +133,7 @@ void bind_to_free_cpu(afl_state_t *afl) {
for (i = 0; i < proccount; i++) {
#if defined(__FreeBSD__)
# if defined(__FreeBSD__)
if (!strcmp(procs[i].ki_comm, "idle")) continue;
// fix when ki_oncpu = -1
@ -143,16 +143,16 @@ void bind_to_free_cpu(afl_state_t *afl) {
if (oncpu != -1 && oncpu < sizeof(cpu_used) && procs[i].ki_pctcpu > 60)
cpu_used[oncpu] = 1;
#elif defined(__DragonFly__)
# elif defined(__DragonFly__)
if (procs[i].kp_lwp.kl_cpuid < sizeof(cpu_used) &&
procs[i].kp_lwp.kl_pctcpu > 10)
cpu_used[procs[i].kp_lwp.kl_cpuid] = 1;
#endif
# endif
}
ck_free(procs);
#elif defined(__NetBSD__)
# elif defined(__NetBSD__)
struct kinfo_proc2 *procs;
size_t nprocs;
size_t proccount;
@ -181,15 +181,15 @@ void bind_to_free_cpu(afl_state_t *afl) {
}
ck_free(procs);
#else
#warning \
"For this platform we do not have free CPU binding code yet. If possible, please supply a PR to https://github.com/AFLplusplus/AFLplusplus"
#endif
# else
# warning \
"For this platform we do not have free CPU binding code yet. If possible, please supply a PR to https://github.com/AFLplusplus/AFLplusplus"
# endif
size_t cpu_start = 0;
try:
#ifndef __ANDROID__
# ifndef __ANDROID__
for (i = cpu_start; i < afl->cpu_core_count; i++) {
if (!cpu_used[i]) { break; }
@ -198,12 +198,12 @@ void bind_to_free_cpu(afl_state_t *afl) {
if (i == afl->cpu_core_count) {
#else
# else
for (i = afl->cpu_core_count - cpu_start - 1; i > -1; i--)
if (!cpu_used[i]) break;
if (i == -1) {
#endif
# endif
SAYF("\n" cLRD "[-] " cRST
"Uh-oh, looks like all %d CPU cores on your system are allocated to\n"
@ -221,16 +221,16 @@ void bind_to_free_cpu(afl_state_t *afl) {
afl->cpu_aff = i;
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
# if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
CPU_ZERO(&c);
CPU_SET(i, &c);
#elif defined(__NetBSD__)
# elif defined(__NetBSD__)
c = cpuset_create();
if (c == NULL) PFATAL("cpuset_create failed");
cpuset_set(i, c);
#endif
# endif
#if defined(__linux__)
# if defined(__linux__)
if (sched_setaffinity(0, sizeof(c), &c)) {
if (cpu_start == afl->cpu_core_count) {
@ -246,7 +246,7 @@ void bind_to_free_cpu(afl_state_t *afl) {
}
#elif defined(__FreeBSD__) || defined(__DragonFly__)
# elif defined(__FreeBSD__) || defined(__DragonFly__)
if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c)) {
if (cpu_start == afl->cpu_core_count)
@ -258,7 +258,7 @@ void bind_to_free_cpu(afl_state_t *afl) {
}
#elif defined(__NetBSD__)
# elif defined(__NetBSD__)
if (pthread_setaffinity_np(pthread_self(), cpuset_size(c), c)) {
if (cpu_start == afl->cpu_core_count)
@ -271,10 +271,10 @@ if (pthread_setaffinity_np(pthread_self(), cpuset_size(c), c)) {
}
cpuset_destroy(c);
#else
# else
// this will need something for other platforms
// TODO: Solaris/Illumos has processor_bind ... might worth a try
#endif
# endif
}
@ -1565,7 +1565,7 @@ void check_crash_handling(void) {
until I get a box to test the code. So, for now, we check for crash
reporting the awful way. */
#if !TARGET_OS_IPHONE
# if !TARGET_OS_IPHONE
if (system("launchctl list 2>/dev/null | grep -q '\\.ReportCrash$'")) return;
SAYF(
@ -1583,7 +1583,7 @@ void check_crash_handling(void) {
" launchctl unload -w ${SL}/LaunchAgents/${PL}.plist\n"
" sudo launchctl unload -w ${SL}/LaunchDaemons/${PL}.Root.plist\n");
#endif
# endif
if (!get_afl_env("AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES"))
FATAL("Crash reporter detected");
@ -1778,26 +1778,26 @@ void get_core_count(afl_state_t *afl) {
/* On *BSD systems, we can just use a sysctl to get the number of CPUs. */
#ifdef __APPLE__
# ifdef __APPLE__
if (sysctlbyname("hw.logicalcpu", &afl->cpu_core_count, &s, NULL, 0) < 0)
return;
#else
# else
int s_name[2] = {CTL_HW, HW_NCPU};
if (sysctl(s_name, 2, &afl->cpu_core_count, &s, NULL, 0) < 0) return;
#endif /* ^__APPLE__ */
# endif /* ^__APPLE__ */
#else
#ifdef HAVE_AFFINITY
# ifdef HAVE_AFFINITY
afl->cpu_core_count = sysconf(_SC_NPROCESSORS_ONLN);
#else
# else
FILE *f = fopen("/proc/stat", "r");
u8 tmp[1024];
@ -1809,7 +1809,7 @@ void get_core_count(afl_state_t *afl) {
fclose(f);
#endif /* ^HAVE_AFFINITY */
# endif /* ^HAVE_AFFINITY */
#endif /* ^(__APPLE__ || __FreeBSD__ || __OpenBSD__) */
@ -2102,12 +2102,12 @@ void check_binary(afl_state_t *afl, u8 *fname) {
#else
#if !defined(__arm__) && !defined(__arm64__)
# if !defined(__arm__) && !defined(__arm64__)
if ((f_data[0] != 0xCF || f_data[1] != 0xFA || f_data[2] != 0xED) &&
(f_data[0] != 0xCA || f_data[1] != 0xFE || f_data[2] != 0xBA))
FATAL("Program '%s' is not a 64-bit or universal Mach-O binary",
afl->fsrv.target_path);
#endif
# endif
#endif /* ^!__APPLE__ */

View File

@ -37,9 +37,9 @@ static void *unsupported(afl_state_t *afl, unsigned int seed) {
/* sorry for this makro...
it just fills in `&py_mutator->something_buf, &py_mutator->something_size`. */
#define BUF_PARAMS(name) \
(void **)&((py_mutator_t *)py_mutator)->name##_buf, \
&((py_mutator_t *)py_mutator)->name##_size
# define BUF_PARAMS(name) \
(void **)&((py_mutator_t *)py_mutator)->name##_buf, \
&((py_mutator_t *)py_mutator)->name##_size
static size_t fuzz_py(void *py_mutator, u8 *buf, size_t buf_size, u8 **out_buf,
u8 *add_buf, size_t add_buf_size, size_t max_size) {
@ -72,11 +72,11 @@ static size_t fuzz_py(void *py_mutator, u8 *buf, size_t buf_size, u8 **out_buf,
PyTuple_SetItem(py_args, 1, py_value);
/* max_size */
#if PY_MAJOR_VERSION >= 3
# if PY_MAJOR_VERSION >= 3
py_value = PyLong_FromLong(max_size);
#else
# else
py_value = PyInt_FromLong(max_size);
#endif
# endif
if (!py_value) {
Py_DECREF(py_args);
@ -118,11 +118,11 @@ static py_mutator_t *init_py_module(afl_state_t *afl, u8 *module_name) {
Py_Initialize();
#if PY_MAJOR_VERSION >= 3
# if PY_MAJOR_VERSION >= 3
PyObject *py_name = PyUnicode_FromString(module_name);
#else
# else
PyObject *py_name = PyString_FromString(module_name);
#endif
# endif
py->py_module = PyImport_Import(py_name);
Py_DECREF(py_name);
@ -243,11 +243,11 @@ static void init_py(afl_state_t *afl, py_mutator_t *py_mutator,
/* Provide the init function a seed for the Python RNG */
py_args = PyTuple_New(1);
#if PY_MAJOR_VERSION >= 3
# if PY_MAJOR_VERSION >= 3
py_value = PyLong_FromLong(seed);
#else
# else
py_value = PyInt_FromLong(seed);
#endif
# endif
if (!py_value) {
@ -440,11 +440,11 @@ s32 init_trim_py(void *py_mutator, u8 *buf, size_t buf_size) {
if (py_value != NULL) {
#if PY_MAJOR_VERSION >= 3
# if PY_MAJOR_VERSION >= 3
u32 retcnt = (u32)PyLong_AsLong(py_value);
#else
# else
u32 retcnt = PyInt_AsLong(py_value);
#endif
# endif
Py_DECREF(py_value);
return retcnt;
@ -479,11 +479,11 @@ s32 post_trim_py(void *py_mutator, u8 success) {
if (py_value != NULL) {
#if PY_MAJOR_VERSION >= 3
# if PY_MAJOR_VERSION >= 3
u32 retcnt = (u32)PyLong_AsLong(py_value);
#else
# else
u32 retcnt = PyInt_AsLong(py_value);
#endif
# endif
Py_DECREF(py_value);
return retcnt;
@ -543,11 +543,11 @@ size_t havoc_mutation_py(void *py_mutator, u8 *buf, size_t buf_size,
PyTuple_SetItem(py_args, 0, py_value);
/* max_size */
#if PY_MAJOR_VERSION >= 3
# if PY_MAJOR_VERSION >= 3
py_value = PyLong_FromLong(max_size);
#else
# else
py_value = PyInt_FromLong(max_size);
#endif
# endif
if (!py_value) {
Py_DECREF(py_args);
@ -625,11 +625,11 @@ u8 queue_get_py(void *py_mutator, const u8 *filename) {
py_args = PyTuple_New(1);
// File name
#if PY_MAJOR_VERSION >= 3
# if PY_MAJOR_VERSION >= 3
py_value = PyUnicode_FromString(filename);
#else
# else
py_value = PyString_FromString(filename);
#endif
# endif
if (!py_value) {
Py_DECREF(py_args);
@ -675,11 +675,11 @@ void queue_new_entry_py(void *py_mutator, const u8 *filename_new_queue,
py_args = PyTuple_New(2);
// New queue
#if PY_MAJOR_VERSION >= 3
# if PY_MAJOR_VERSION >= 3
py_value = PyUnicode_FromString(filename_new_queue);
#else
# else
py_value = PyString_FromString(filename_new_queue);
#endif
# endif
if (!py_value) {
Py_DECREF(py_args);
@ -693,11 +693,11 @@ void queue_new_entry_py(void *py_mutator, const u8 *filename_new_queue,
py_value = Py_None;
if (filename_orig_queue) {
#if PY_MAJOR_VERSION >= 3
# if PY_MAJOR_VERSION >= 3
py_value = PyUnicode_FromString(filename_orig_queue);
#else
# else
py_value = PyString_FromString(filename_orig_queue);
#endif
# endif
if (!py_value) {
Py_DECREF(py_args);
@ -724,7 +724,7 @@ void queue_new_entry_py(void *py_mutator, const u8 *filename_new_queue,
}
#undef BUF_PARAMS
# undef BUF_PARAMS
#endif /* USE_PYTHON */

View File

@ -853,7 +853,7 @@ int main(int argc, char **argv_orig, char **envp) {
}
#if defined(__SANITIZE_ADDRESS__)
# if defined(__SANITIZE_ADDRESS__)
if (afl->fsrv.mem_limit) {
WARNF("in the ASAN build we disable all memory limits");
@ -861,7 +861,7 @@ int main(int argc, char **argv_orig, char **envp) {
}
#endif
# endif
setup_signal_handlers();
check_asan_opts();
@ -1054,9 +1054,9 @@ int main(int argc, char **argv_orig, char **envp) {
get_core_count(afl);
#ifdef HAVE_AFFINITY
# ifdef HAVE_AFFINITY
bind_to_free_cpu(afl);
#endif /* HAVE_AFFINITY */
# endif /* HAVE_AFFINITY */
check_crash_handling();
check_cpu_governor(afl);
@ -1352,12 +1352,12 @@ stop_fuzzing:
}
#ifdef PROFILING
# ifdef PROFILING
SAYF(cYEL "[!] " cRST
"Profiling information: %llu ms total work, %llu ns/run\n",
time_spent_working / 1000000,
time_spent_working / afl->fsrv.total_execs);
#endif
# endif
fclose(afl->fsrv.plot_file);
destroy_queue(afl);

View File

@ -32,11 +32,11 @@
#define AFL_MAIN
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
# define _GNU_SOURCE
#endif
#ifdef __ANDROID__
#include "android-ashmem.h"
# include "android-ashmem.h"
#endif
#include <stdio.h>
#include <stdlib.h>
@ -55,22 +55,22 @@
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
defined(__APPLE__) || defined(__DragonFly__)
#define HAVE_AFFINITY 1
#if defined(__FreeBSD__) || defined(__DragonFly__)
#include <pthread.h>
#include <pthread_np.h>
#if defined(__FreeBSD__)
#include <sys/cpuset.h>
#endif
#define cpu_set_t cpuset_t
#elif defined(__NetBSD__)
#include <pthread.h>
#include <sched.h>
#elif defined(__APPLE__)
#include <pthread.h>
#include <mach/thread_act.h>
#include <mach/thread_policy.h>
#endif
# define HAVE_AFFINITY 1
# if defined(__FreeBSD__) || defined(__DragonFly__)
# include <pthread.h>
# include <pthread_np.h>
# if defined(__FreeBSD__)
# include <sys/cpuset.h>
# endif
# define cpu_set_t cpuset_t
# elif defined(__NetBSD__)
# include <pthread.h>
# include <sched.h>
# elif defined(__APPLE__)
# include <pthread.h>
# include <mach/thread_act.h>
# include <mach/thread_policy.h>
# endif
#endif /* __linux__ || __FreeBSD__ || __NetBSD__ || __APPLE__ */
/* Get CPU usage in microseconds. */
@ -163,46 +163,46 @@ int main(int argc, char **argv) {
if (!fr) {
u32 util_perc;
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
# if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
cpu_set_t c;
CPU_ZERO(&c);
CPU_SET(i, &c);
#elif defined(__NetBSD__)
# elif defined(__NetBSD__)
cpuset_t *c;
c = cpuset_create();
if (c == NULL) PFATAL("cpuset_create failed");
cpuset_set(i, c);
#elif defined(__APPLE__)
# elif defined(__APPLE__)
thread_affinity_policy_data_t c = {i};
thread_port_t native_thread = pthread_mach_thread_np(pthread_self());
if (thread_policy_set(native_thread, THREAD_AFFINITY_POLICY,
(thread_policy_t)&c, 1) != KERN_SUCCESS)
PFATAL("thread_policy_set failed");
#endif
# endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
# if defined(__FreeBSD__) || defined(__DragonFly__)
if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c))
PFATAL("pthread_setaffinity_np failed");
#endif
# endif
#if defined(__NetBSD__)
# if defined(__NetBSD__)
if (pthread_setaffinity_np(pthread_self(), cpuset_size(c), c))
PFATAL("pthread_setaffinity_np failed");
cpuset_destroy(c);
#endif
# endif
#if defined(__linux__)
# if defined(__linux__)
if (sched_setaffinity(0, sizeof(c), &c)) {
PFATAL("sched_setaffinity failed for cpu %d", i);
}
#endif
# endif
util_perc = measure_preemption(CTEST_CORE_TRG_MS);

View File

@ -27,7 +27,7 @@
#define AFL_MAIN
#ifdef __ANDROID__
#include "android-ashmem.h"
# include "android-ashmem.h"
#endif
#include "config.h"
#include "types.h"
@ -56,8 +56,8 @@
#include <sys/mman.h>
#ifndef USEMMAP
#include <sys/ipc.h>
#include <sys/shm.h>
# include <sys/ipc.h>
# include <sys/shm.h>
#endif
static list_t shm_list = {.element_prealloc_count = 0};

View File

@ -32,7 +32,7 @@
#define AFL_MAIN
#ifdef __ANDROID__
#include "android-ashmem.h"
# include "android-ashmem.h"
#endif
#include "config.h"
#include "types.h"

View File

@ -30,7 +30,7 @@
#define AFL_MAIN
#ifdef __ANDROID__
#include "android-ashmem.h"
# include "android-ashmem.h"
#endif
#include "config.h"