From a161aac7c1eb8b689f4afc818b25072796e62746 Mon Sep 17 00:00:00 2001 From: Giovanni Di Santi Date: Sat, 29 Jun 2024 22:05:22 +0200 Subject: ijon set: init --- instrumentation/afl-compiler-rt.o.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'instrumentation') diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c index c08e6380..bf498781 100644 --- a/instrumentation/afl-compiler-rt.o.c +++ b/instrumentation/afl-compiler-rt.o.c @@ -2761,5 +2761,11 @@ void __afl_injection_xss(u8 *buf) { } +void __afl_ijon_set(u32 edge) { + + __afl_area_ptr[edge % __afl_map_size] |= 1; + +} + #undef write_error -- cgit 1.4.1 From 8fbeeb143989f4ebbcc238a96305e4c534e074c7 Mon Sep 17 00:00:00 2001 From: Giovanni Di Santi Date: Sun, 30 Jun 2024 15:50:37 +0200 Subject: ijon set: discard source code instrumentation --- frida_mode/src/instrument/instrument.c | 2 +- instrumentation/afl-compiler-rt.o.c | 6 ------ src/afl-cc.c | 7 ++----- 3 files changed, 3 insertions(+), 12 deletions(-) (limited to 'instrumentation') diff --git a/frida_mode/src/instrument/instrument.c b/frida_mode/src/instrument/instrument.c index cbb8afd9..e0495cdf 100644 --- a/frida_mode/src/instrument/instrument.c +++ b/frida_mode/src/instrument/instrument.c @@ -451,7 +451,7 @@ void instrument_regs_format(int fd, char *format, ...) { void ijon_set(uint32_t edge) { - __afl_ijon_set(edge); + __afl_area_ptr[edge % __afl_map_size] |= 1; } diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c index bf498781..c08e6380 100644 --- a/instrumentation/afl-compiler-rt.o.c +++ b/instrumentation/afl-compiler-rt.o.c @@ -2761,11 +2761,5 @@ void __afl_injection_xss(u8 *buf) { } -void __afl_ijon_set(u32 edge) { - - __afl_area_ptr[edge % __afl_map_size] |= 1; - -} - #undef write_error diff --git a/src/afl-cc.c b/src/afl-cc.c index 2a027ce4..7afab850 100644 --- a/src/afl-cc.c +++ b/src/afl-cc.c @@ -1528,8 +1528,7 @@ void add_defs_selective_instr(aflcc_state_t *aflcc) { "extern \"C\" void __afl_coverage_discard();" "extern \"C\" void __afl_coverage_skip();" "extern \"C\" void __afl_coverage_on();" - "extern \"C\" void __afl_coverage_off();" - "extern \"C\" void __afl_ijon_set(unsigned int);"); + "extern \"C\" void __afl_coverage_off();"); } else { @@ -1538,8 +1537,7 @@ void add_defs_selective_instr(aflcc_state_t *aflcc) { "void __afl_coverage_discard();" "void __afl_coverage_skip();" "void __afl_coverage_on();" - "void __afl_coverage_off();" - "void __afl_ijon_set(unsigned int);"); + "void __afl_coverage_off();"); } @@ -1551,7 +1549,6 @@ void add_defs_selective_instr(aflcc_state_t *aflcc) { insert_param(aflcc, "-D__AFL_COVERAGE_OFF()=__afl_coverage_off()"); insert_param(aflcc, "-D__AFL_COVERAGE_DISCARD()=__afl_coverage_discard()"); insert_param(aflcc, "-D__AFL_COVERAGE_SKIP()=__afl_coverage_skip()"); - insert_param(aflcc, "-D__AFL_IJON_SET(_A)=__afl_ijon_set(_A)"); } -- cgit 1.4.1 From 77bad3ad239c557d17ab2788837d2a7aa854b235 Mon Sep 17 00:00:00 2001 From: Giovanni Di Santi Date: Wed, 10 Jul 2024 10:16:14 +0200 Subject: ijon set: use __afl_coverage_interesting --- dynamic_list.txt | 1 - frida_mode/include/instrument.h | 2 +- frida_mode/src/instrument/instrument.c | 2 +- instrumentation/afl-compiler-rt.o.c | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) (limited to 'instrumentation') diff --git a/dynamic_list.txt b/dynamic_list.txt index 1a5c514a..50c0c6b8 100644 --- a/dynamic_list.txt +++ b/dynamic_list.txt @@ -30,7 +30,6 @@ "__afl_selective_coverage_temp"; "__afl_sharedmem_fuzzing"; "__afl_trace"; - "__afl_ijon_set"; "__cmplog_ins_hook1"; "__cmplog_ins_hook16"; "__cmplog_ins_hook2"; diff --git a/frida_mode/include/instrument.h b/frida_mode/include/instrument.h index 7f4958a2..a1969e37 100644 --- a/frida_mode/include/instrument.h +++ b/frida_mode/include/instrument.h @@ -22,7 +22,7 @@ extern guint64 instrument_fixed_seed; extern uint8_t *__afl_area_ptr; extern uint32_t __afl_map_size; -extern void __afl_ijon_set(uint32_t); +extern void __afl_coverage_interesting(uint8_t, uint32_t); extern __thread guint64 *instrument_previous_pc_addr; diff --git a/frida_mode/src/instrument/instrument.c b/frida_mode/src/instrument/instrument.c index e0495cdf..d30e21ec 100644 --- a/frida_mode/src/instrument/instrument.c +++ b/frida_mode/src/instrument/instrument.c @@ -451,7 +451,7 @@ void instrument_regs_format(int fd, char *format, ...) { void ijon_set(uint32_t edge) { - __afl_area_ptr[edge % __afl_map_size] |= 1; + __afl_coverage_interesting(1, edge); } diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c index c08e6380..f28f5ea4 100644 --- a/instrumentation/afl-compiler-rt.o.c +++ b/instrumentation/afl-compiler-rt.o.c @@ -2704,7 +2704,7 @@ void __afl_coverage_skip() { // mark this area as especially interesting void __afl_coverage_interesting(u8 val, u32 id) { - __afl_area_ptr[id] = val; + __afl_area_ptr[id % __afl_map_size] = val; } -- cgit 1.4.1 From 7c380a6612f00e4a7ed02364dc2b3769e8edc8f8 Mon Sep 17 00:00:00 2001 From: carpintero-de-c <175505615+carpintero-de-c@users.noreply.github.com> Date: Sun, 14 Jul 2024 03:55:58 +0530 Subject: Replace gettimeofday with clock_gettime (#2159) --- custom_mutators/gramatron/test.c | 23 ++++++++++------------- custom_mutators/symqemu/symqemu.c | 7 +++---- frida_mode/test/unstable/unstable.c | 31 +++++++++++++++++++++---------- include/afl-fuzz.h | 1 - instrumentation/afl-llvm-pass.so.cc | 9 ++++----- src/afl-as.c | 8 +++----- src/afl-common.c | 15 ++++++--------- src/afl-fuzz.c | 7 +++---- 8 files changed, 50 insertions(+), 51 deletions(-) (limited to 'instrumentation') diff --git a/custom_mutators/gramatron/test.c b/custom_mutators/gramatron/test.c index 0dfbc197..3577faa1 100644 --- a/custom_mutators/gramatron/test.c +++ b/custom_mutators/gramatron/test.c @@ -8,8 +8,8 @@ state *create_pda(u8 *automaton_file) { struct json_object *parsed_json; - state * pda; - json_object * source_obj, *attr; + state *pda; + json_object *source_obj, *attr; int arraylen, ii, ii2, trigger_len, error; printf("\n[GF] Automaton file passed:%s", automaton_file); @@ -41,7 +41,7 @@ state *create_pda(u8 *automaton_file) { enum json_type type; json_object_object_foreach(source_obj, key, val) { - state * state_ptr; + state *state_ptr; trigger *trigger_ptr; int offset; @@ -97,12 +97,12 @@ state *create_pda(u8 *automaton_file) { void SanityCheck(char *automaton_path) { - state * pda = create_pda(automaton_path); + state *pda = create_pda(automaton_path); int count = 0, state; Get_Dupes_Ret *getdupesret; - IdxMap_new * statemap; - IdxMap_new * statemap_ptr; - terminal * term_ptr; + IdxMap_new *statemap; + IdxMap_new *statemap_ptr; + terminal *term_ptr; while (count < NUMINPUTS) { @@ -117,12 +117,9 @@ void SanityCheck(char *automaton_path) { int main(int argc, char *argv[]) { - char * mode; - char * automaton_path; - char * output_dir = NULL; - struct timeval tv; - struct timeval tz; - // gettimeofday(&tv, &tz); + char *mode; + char *automaton_path; + char *output_dir = NULL; srand(1337); if (argc == 3) { diff --git a/custom_mutators/symqemu/symqemu.c b/custom_mutators/symqemu/symqemu.c index 73a1640a..b9912923 100644 --- a/custom_mutators/symqemu/symqemu.c +++ b/custom_mutators/symqemu/symqemu.c @@ -196,12 +196,11 @@ void afl_custom_splice_optout(void *data) { inline u64 get_cur_time(void) { - struct timeval tv; - struct timezone tz; + struct timespec spec; - gettimeofday(&tv, &tz); + clock_gettime(CLOCK_REALTIME, &spec); - return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000); + return (spec.tv_sec * 1000ULL) + (spec.tv_nsec / 1000000ULL); } diff --git a/frida_mode/test/unstable/unstable.c b/frida_mode/test/unstable/unstable.c index 16978e7e..8466cba0 100644 --- a/frida_mode/test/unstable/unstable.c +++ b/frida_mode/test/unstable/unstable.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #ifdef __APPLE__ #define TESTINSTR_SECTION @@ -22,17 +22,21 @@ #define TESTINSTR_SECTION __attribute__((section(".testinstr"))) #endif -void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { +void LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (size < 1) return; - struct timeval tv = {0}; - if (gettimeofday(&tv, NULL) < 0) return; + struct timespec spec = {0}; + if (clock_gettime(CLOCK_REALTIME, &spec) < 0) return; + + if ((spec.tv_nsec % 2) == 0) { + + printf("Hooray all even\n"); - if ((tv.tv_usec % 2) == 0) { - printf ("Hooray all even\n"); } else { - printf ("Hmm that's odd\n"); + + printf("Hmm that's odd\n"); + } // we support three input cases @@ -45,26 +49,33 @@ void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { } -void run_test(char * file) { +void run_test(char *file) { + fprintf(stderr, "Running: %s\n", file); FILE *f = fopen(file, "r"); assert(f); fseek(f, 0, SEEK_END); size_t len = ftell(f); fseek(f, 0, SEEK_SET); - unsigned char *buf = (unsigned char*)malloc(len); - size_t n_read = fread(buf, 1, len, f); + unsigned char *buf = (unsigned char *)malloc(len); + size_t n_read = fread(buf, 1, len, f); fclose(f); assert(n_read == len); LLVMFuzzerTestOneInput(buf, len); free(buf); fprintf(stderr, "Done: %s: (%zd bytes)\n", file, n_read); + } int main(int argc, char **argv) { + srand(1); fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1); for (int i = 1; i < argc; i++) { + run_test(argv[i]); + } + } + diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h index 0f0e45d3..a7526aff 100644 --- a/include/afl-fuzz.h +++ b/include/afl-fuzz.h @@ -64,7 +64,6 @@ #include #include -#include #ifndef USEMMAP #include #endif diff --git a/instrumentation/afl-llvm-pass.so.cc b/instrumentation/afl-llvm-pass.so.cc index 75b8532b..fb5b856c 100644 --- a/instrumentation/afl-llvm-pass.so.cc +++ b/instrumentation/afl-llvm-pass.so.cc @@ -32,12 +32,12 @@ #include "debug.h" #include #include +#include #include #include #include #include -#include #include "llvm/Config/llvm-config.h" #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 5 @@ -211,14 +211,13 @@ bool AFLCoverage::runOnModule(Module &M) { IntegerType *IntLocTy = IntegerType::getIntNTy(C, sizeof(PREV_LOC_T) * CHAR_BIT); #endif - struct timeval tv; - struct timezone tz; + struct timespec spec; u32 rand_seed; unsigned int cur_loc = 0; /* Setup random() so we get Actually Random(TM) outputs from AFL_R() */ - gettimeofday(&tv, &tz); - rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid(); + clock_gettime(CLOCK_REALTIME, &spec); + rand_seed = spec.tv_sec ^ spec.tv_nsec ^ getpid(); AFL_SR(rand_seed); /* Show a banner */ diff --git a/src/afl-as.c b/src/afl-as.c index d4ddb94d..df487cbc 100644 --- a/src/afl-as.c +++ b/src/afl-as.c @@ -52,7 +52,6 @@ #include #include -#include static u8 **as_params; /* Parameters passed to the real 'as' */ @@ -557,8 +556,7 @@ int main(int argc, char **argv) { int status; u8 *inst_ratio_str = getenv("AFL_INST_RATIO"); - struct timeval tv; - struct timezone tz; + struct timespec spec; clang_mode = !!getenv(CLANG_ENV_VAR); @@ -609,9 +607,9 @@ int main(int argc, char **argv) { } - gettimeofday(&tv, &tz); + clock_gettime(CLOCK_REALTIME, &spec); - rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid(); + rand_seed = spec.tv_sec ^ spec.tv_nsec ^ getpid(); // in fast systems where pids can repeat in the same seconds we need this for (i = 1; (s32)i < argc; i++) for (j = 0; j < strlen(argv[i]); j++) diff --git a/src/afl-common.c b/src/afl-common.c index efdb5d60..62432158 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -976,12 +976,11 @@ void read_bitmap(u8 *fname, u8 *map, size_t len) { inline u64 get_cur_time(void) { - struct timeval tv; - struct timezone tz; + struct timespec spec; - gettimeofday(&tv, &tz); + clock_gettime(CLOCK_REALTIME, &spec); - return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000); + return (spec.tv_sec * 1000ULL) + (spec.tv_nsec / 1000000ULL); } @@ -989,19 +988,17 @@ inline u64 get_cur_time(void) { inline u64 get_cur_time_us(void) { - struct timeval tv; - struct timezone tz; + struct timespec spec; - gettimeofday(&tv, &tz); + clock_gettime(CLOCK_REALTIME, &spec); - return (tv.tv_sec * 1000000ULL) + tv.tv_usec; + return (spec.tv_sec * 1000000ULL) + (spec.tv_nsec / 1000ULL); } /* Describe integer. The buf should be at least 6 bytes to fit all ints we randomly see. Will return buf for convenience. */ - u8 *stringify_int(u8 *buf, size_t len, u64 val) { \ #define CHK_FORMAT(_divisor, _limit_mult, _fmt, _cast) \ diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c index 9867eba3..0f84b79b 100644 --- a/src/afl-fuzz.c +++ b/src/afl-fuzz.c @@ -555,8 +555,7 @@ int main(int argc, char **argv_orig, char **envp) { char *frida_afl_preload = NULL; char **use_argv; - struct timeval tv; - struct timezone tz; + struct timespec spec; doc_path = access(DOC_PATH, F_OK) != 0 ? (u8 *)"docs" : (u8 *)DOC_PATH; @@ -603,8 +602,8 @@ int main(int argc, char **argv_orig, char **envp) { SAYF(cCYA "afl-fuzz" VERSION cRST " based on afl by Michal Zalewski and a large online community\n"); - gettimeofday(&tv, &tz); - rand_set_seed(afl, tv.tv_sec ^ tv.tv_usec ^ getpid()); + clock_gettime(CLOCK_REALTIME, &spec); + rand_set_seed(afl, spec.tv_sec ^ spec.tv_nsec ^ getpid()); afl->shmem_testcase_mode = 1; // we always try to perform shmem fuzzing -- cgit 1.4.1 From ccb952dde8dbf2165a0d84308e558cd68679fb13 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Sun, 14 Jul 2024 10:18:23 +0200 Subject: Revert "Replace gettimeofday with clock_gettime (#2159)" This reverts commit 7c380a6612f00e4a7ed02364dc2b3769e8edc8f8. --- custom_mutators/gramatron/test.c | 23 +++++++++++++---------- custom_mutators/symqemu/symqemu.c | 7 ++++--- frida_mode/test/unstable/unstable.c | 31 ++++++++++--------------------- include/afl-fuzz.h | 1 + instrumentation/afl-llvm-pass.so.cc | 9 +++++---- src/afl-as.c | 8 +++++--- src/afl-common.c | 15 +++++++++------ src/afl-fuzz.c | 7 ++++--- 8 files changed, 51 insertions(+), 50 deletions(-) (limited to 'instrumentation') diff --git a/custom_mutators/gramatron/test.c b/custom_mutators/gramatron/test.c index 3577faa1..0dfbc197 100644 --- a/custom_mutators/gramatron/test.c +++ b/custom_mutators/gramatron/test.c @@ -8,8 +8,8 @@ state *create_pda(u8 *automaton_file) { struct json_object *parsed_json; - state *pda; - json_object *source_obj, *attr; + state * pda; + json_object * source_obj, *attr; int arraylen, ii, ii2, trigger_len, error; printf("\n[GF] Automaton file passed:%s", automaton_file); @@ -41,7 +41,7 @@ state *create_pda(u8 *automaton_file) { enum json_type type; json_object_object_foreach(source_obj, key, val) { - state *state_ptr; + state * state_ptr; trigger *trigger_ptr; int offset; @@ -97,12 +97,12 @@ state *create_pda(u8 *automaton_file) { void SanityCheck(char *automaton_path) { - state *pda = create_pda(automaton_path); + state * pda = create_pda(automaton_path); int count = 0, state; Get_Dupes_Ret *getdupesret; - IdxMap_new *statemap; - IdxMap_new *statemap_ptr; - terminal *term_ptr; + IdxMap_new * statemap; + IdxMap_new * statemap_ptr; + terminal * term_ptr; while (count < NUMINPUTS) { @@ -117,9 +117,12 @@ void SanityCheck(char *automaton_path) { int main(int argc, char *argv[]) { - char *mode; - char *automaton_path; - char *output_dir = NULL; + char * mode; + char * automaton_path; + char * output_dir = NULL; + struct timeval tv; + struct timeval tz; + // gettimeofday(&tv, &tz); srand(1337); if (argc == 3) { diff --git a/custom_mutators/symqemu/symqemu.c b/custom_mutators/symqemu/symqemu.c index b9912923..73a1640a 100644 --- a/custom_mutators/symqemu/symqemu.c +++ b/custom_mutators/symqemu/symqemu.c @@ -196,11 +196,12 @@ void afl_custom_splice_optout(void *data) { inline u64 get_cur_time(void) { - struct timespec spec; + struct timeval tv; + struct timezone tz; - clock_gettime(CLOCK_REALTIME, &spec); + gettimeofday(&tv, &tz); - return (spec.tv_sec * 1000ULL) + (spec.tv_nsec / 1000000ULL); + return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000); } diff --git a/frida_mode/test/unstable/unstable.c b/frida_mode/test/unstable/unstable.c index 8466cba0..16978e7e 100644 --- a/frida_mode/test/unstable/unstable.c +++ b/frida_mode/test/unstable/unstable.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #ifdef __APPLE__ #define TESTINSTR_SECTION @@ -22,21 +22,17 @@ #define TESTINSTR_SECTION __attribute__((section(".testinstr"))) #endif -void LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { +void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (size < 1) return; - struct timespec spec = {0}; - if (clock_gettime(CLOCK_REALTIME, &spec) < 0) return; - - if ((spec.tv_nsec % 2) == 0) { - - printf("Hooray all even\n"); + struct timeval tv = {0}; + if (gettimeofday(&tv, NULL) < 0) return; + if ((tv.tv_usec % 2) == 0) { + printf ("Hooray all even\n"); } else { - - printf("Hmm that's odd\n"); - + printf ("Hmm that's odd\n"); } // we support three input cases @@ -49,33 +45,26 @@ void LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { } -void run_test(char *file) { - +void run_test(char * file) { fprintf(stderr, "Running: %s\n", file); FILE *f = fopen(file, "r"); assert(f); fseek(f, 0, SEEK_END); size_t len = ftell(f); fseek(f, 0, SEEK_SET); - unsigned char *buf = (unsigned char *)malloc(len); - size_t n_read = fread(buf, 1, len, f); + unsigned char *buf = (unsigned char*)malloc(len); + size_t n_read = fread(buf, 1, len, f); fclose(f); assert(n_read == len); LLVMFuzzerTestOneInput(buf, len); free(buf); fprintf(stderr, "Done: %s: (%zd bytes)\n", file, n_read); - } int main(int argc, char **argv) { - srand(1); fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1); for (int i = 1; i < argc; i++) { - run_test(argv[i]); - } - } - diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h index a7526aff..0f0e45d3 100644 --- a/include/afl-fuzz.h +++ b/include/afl-fuzz.h @@ -64,6 +64,7 @@ #include #include +#include #ifndef USEMMAP #include #endif diff --git a/instrumentation/afl-llvm-pass.so.cc b/instrumentation/afl-llvm-pass.so.cc index fb5b856c..75b8532b 100644 --- a/instrumentation/afl-llvm-pass.so.cc +++ b/instrumentation/afl-llvm-pass.so.cc @@ -32,12 +32,12 @@ #include "debug.h" #include #include -#include #include #include #include #include +#include #include "llvm/Config/llvm-config.h" #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 5 @@ -211,13 +211,14 @@ bool AFLCoverage::runOnModule(Module &M) { IntegerType *IntLocTy = IntegerType::getIntNTy(C, sizeof(PREV_LOC_T) * CHAR_BIT); #endif - struct timespec spec; + struct timeval tv; + struct timezone tz; u32 rand_seed; unsigned int cur_loc = 0; /* Setup random() so we get Actually Random(TM) outputs from AFL_R() */ - clock_gettime(CLOCK_REALTIME, &spec); - rand_seed = spec.tv_sec ^ spec.tv_nsec ^ getpid(); + gettimeofday(&tv, &tz); + rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid(); AFL_SR(rand_seed); /* Show a banner */ diff --git a/src/afl-as.c b/src/afl-as.c index df487cbc..d4ddb94d 100644 --- a/src/afl-as.c +++ b/src/afl-as.c @@ -52,6 +52,7 @@ #include #include +#include static u8 **as_params; /* Parameters passed to the real 'as' */ @@ -556,7 +557,8 @@ int main(int argc, char **argv) { int status; u8 *inst_ratio_str = getenv("AFL_INST_RATIO"); - struct timespec spec; + struct timeval tv; + struct timezone tz; clang_mode = !!getenv(CLANG_ENV_VAR); @@ -607,9 +609,9 @@ int main(int argc, char **argv) { } - clock_gettime(CLOCK_REALTIME, &spec); + gettimeofday(&tv, &tz); - rand_seed = spec.tv_sec ^ spec.tv_nsec ^ getpid(); + rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid(); // in fast systems where pids can repeat in the same seconds we need this for (i = 1; (s32)i < argc; i++) for (j = 0; j < strlen(argv[i]); j++) diff --git a/src/afl-common.c b/src/afl-common.c index 62432158..efdb5d60 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -976,11 +976,12 @@ void read_bitmap(u8 *fname, u8 *map, size_t len) { inline u64 get_cur_time(void) { - struct timespec spec; + struct timeval tv; + struct timezone tz; - clock_gettime(CLOCK_REALTIME, &spec); + gettimeofday(&tv, &tz); - return (spec.tv_sec * 1000ULL) + (spec.tv_nsec / 1000000ULL); + return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000); } @@ -988,17 +989,19 @@ inline u64 get_cur_time(void) { inline u64 get_cur_time_us(void) { - struct timespec spec; + struct timeval tv; + struct timezone tz; - clock_gettime(CLOCK_REALTIME, &spec); + gettimeofday(&tv, &tz); - return (spec.tv_sec * 1000000ULL) + (spec.tv_nsec / 1000ULL); + return (tv.tv_sec * 1000000ULL) + tv.tv_usec; } /* Describe integer. The buf should be at least 6 bytes to fit all ints we randomly see. Will return buf for convenience. */ + u8 *stringify_int(u8 *buf, size_t len, u64 val) { \ #define CHK_FORMAT(_divisor, _limit_mult, _fmt, _cast) \ diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c index 0f84b79b..9867eba3 100644 --- a/src/afl-fuzz.c +++ b/src/afl-fuzz.c @@ -555,7 +555,8 @@ int main(int argc, char **argv_orig, char **envp) { char *frida_afl_preload = NULL; char **use_argv; - struct timespec spec; + struct timeval tv; + struct timezone tz; doc_path = access(DOC_PATH, F_OK) != 0 ? (u8 *)"docs" : (u8 *)DOC_PATH; @@ -602,8 +603,8 @@ int main(int argc, char **argv_orig, char **envp) { SAYF(cCYA "afl-fuzz" VERSION cRST " based on afl by Michal Zalewski and a large online community\n"); - clock_gettime(CLOCK_REALTIME, &spec); - rand_set_seed(afl, spec.tv_sec ^ spec.tv_nsec ^ getpid()); + gettimeofday(&tv, &tz); + rand_set_seed(afl, tv.tv_sec ^ tv.tv_usec ^ getpid()); afl->shmem_testcase_mode = 1; // we always try to perform shmem fuzzing -- cgit 1.4.1