Revert "Replace gettimeofday with clock_gettime (#2159)"

This reverts commit 7c380a6612.
This commit is contained in:
vanhauser-thc
2024-07-14 10:18:23 +02:00
parent 7c380a6612
commit ccb952dde8
8 changed files with 51 additions and 50 deletions

View File

@ -120,6 +120,9 @@ int main(int argc, char *argv[]) {
char * mode; char * mode;
char * automaton_path; char * automaton_path;
char * output_dir = NULL; char * output_dir = NULL;
struct timeval tv;
struct timeval tz;
// gettimeofday(&tv, &tz);
srand(1337); srand(1337);
if (argc == 3) { if (argc == 3) {

View File

@ -196,11 +196,12 @@ void afl_custom_splice_optout(void *data) {
inline u64 get_cur_time(void) { 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);
} }

View File

@ -14,7 +14,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <sys/time.h>
#ifdef __APPLE__ #ifdef __APPLE__
#define TESTINSTR_SECTION #define TESTINSTR_SECTION
@ -26,17 +26,13 @@ void LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < 1) return; if (size < 1) return;
struct timespec spec = {0}; struct timeval tv = {0};
if (clock_gettime(CLOCK_REALTIME, &spec) < 0) return; if (gettimeofday(&tv, NULL) < 0) return;
if ((spec.tv_nsec % 2) == 0) {
if ((tv.tv_usec % 2) == 0) {
printf ("Hooray all even\n"); printf ("Hooray all even\n");
} else { } else {
printf ("Hmm that's odd\n"); printf ("Hmm that's odd\n");
} }
// we support three input cases // we support three input cases
@ -50,7 +46,6 @@ 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); fprintf(stderr, "Running: %s\n", file);
FILE *f = fopen(file, "r"); FILE *f = fopen(file, "r");
assert(f); assert(f);
@ -64,18 +59,12 @@ void run_test(char *file) {
LLVMFuzzerTestOneInput(buf, len); LLVMFuzzerTestOneInput(buf, len);
free(buf); free(buf);
fprintf(stderr, "Done: %s: (%zd bytes)\n", file, n_read); fprintf(stderr, "Done: %s: (%zd bytes)\n", file, n_read);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
srand(1); srand(1);
fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1); fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1);
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
run_test(argv[i]); run_test(argv[i]);
} }
} }

View File

@ -64,6 +64,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/time.h>
#ifndef USEMMAP #ifndef USEMMAP
#include <sys/shm.h> #include <sys/shm.h>
#endif #endif

View File

@ -32,12 +32,12 @@
#include "debug.h" #include "debug.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <list> #include <list>
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <sys/time.h>
#include "llvm/Config/llvm-config.h" #include "llvm/Config/llvm-config.h"
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 5 #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 5
@ -211,13 +211,14 @@ bool AFLCoverage::runOnModule(Module &M) {
IntegerType *IntLocTy = IntegerType *IntLocTy =
IntegerType::getIntNTy(C, sizeof(PREV_LOC_T) * CHAR_BIT); IntegerType::getIntNTy(C, sizeof(PREV_LOC_T) * CHAR_BIT);
#endif #endif
struct timespec spec; struct timeval tv;
struct timezone tz;
u32 rand_seed; u32 rand_seed;
unsigned int cur_loc = 0; unsigned int cur_loc = 0;
/* Setup random() so we get Actually Random(TM) outputs from AFL_R() */ /* Setup random() so we get Actually Random(TM) outputs from AFL_R() */
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();
AFL_SR(rand_seed); AFL_SR(rand_seed);
/* Show a banner */ /* Show a banner */

View File

@ -52,6 +52,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/time.h>
static u8 **as_params; /* Parameters passed to the real 'as' */ static u8 **as_params; /* Parameters passed to the real 'as' */
@ -556,7 +557,8 @@ int main(int argc, char **argv) {
int status; int status;
u8 *inst_ratio_str = getenv("AFL_INST_RATIO"); u8 *inst_ratio_str = getenv("AFL_INST_RATIO");
struct timespec spec; struct timeval tv;
struct timezone tz;
clang_mode = !!getenv(CLANG_ENV_VAR); 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 // in fast systems where pids can repeat in the same seconds we need this
for (i = 1; (s32)i < argc; i++) for (i = 1; (s32)i < argc; i++)
for (j = 0; j < strlen(argv[i]); j++) for (j = 0; j < strlen(argv[i]); j++)

View File

@ -976,11 +976,12 @@ void read_bitmap(u8 *fname, u8 *map, size_t len) {
inline u64 get_cur_time(void) { 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) { 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 /* Describe integer. The buf should be
at least 6 bytes to fit all ints we randomly see. at least 6 bytes to fit all ints we randomly see.
Will return buf for convenience. */ Will return buf for convenience. */
u8 *stringify_int(u8 *buf, size_t len, u64 val) { u8 *stringify_int(u8 *buf, size_t len, u64 val) {
\ \
#define CHK_FORMAT(_divisor, _limit_mult, _fmt, _cast) \ #define CHK_FORMAT(_divisor, _limit_mult, _fmt, _cast) \

View File

@ -555,7 +555,8 @@ int main(int argc, char **argv_orig, char **envp) {
char *frida_afl_preload = NULL; char *frida_afl_preload = NULL;
char **use_argv; 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; 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 SAYF(cCYA "afl-fuzz" VERSION cRST
" based on afl by Michal Zalewski and a large online community\n"); " based on afl by Michal Zalewski and a large online community\n");
clock_gettime(CLOCK_REALTIME, &spec); gettimeofday(&tv, &tz);
rand_set_seed(afl, spec.tv_sec ^ spec.tv_nsec ^ getpid()); rand_set_seed(afl, tv.tv_sec ^ tv.tv_usec ^ getpid());
afl->shmem_testcase_mode = 1; // we always try to perform shmem fuzzing afl->shmem_testcase_mode = 1; // we always try to perform shmem fuzzing