1 #include "chewing_fuzzer_common.h" 2 3 #include <libgen.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <string.h> 7 8 static char userphrase_path[] = "/tmp/chewing_userphrase.db.XXXXXX"; 9 LLVMFuzzerInitialize(int * argc,char *** argv)10int LLVMFuzzerInitialize(int* argc, char*** argv) { 11 char* exe_path = (*argv)[0]; 12 13 // dirname() can modify its argument. 14 char* exe_path_copy = strdup(exe_path); 15 char* dir = dirname(exe_path_copy); 16 17 // Assume data files are at the same location as executable. 18 setenv("CHEWING_PATH", dir, 0); 19 free(exe_path_copy); 20 21 // Specify user db of this process. So we can run multiple fuzzers at the 22 // same time. 23 mktemp(userphrase_path); 24 setenv("TEST_USERPHRASE_PATH", userphrase_path, 0); 25 return 0; 26 } 27 get_fuzz_input()28int get_fuzz_input() { 29 if (fuzz_ptr - fuzz_input >= fuzz_size) 30 return EOF; 31 return *fuzz_ptr++; 32 } 33