From 4103ee43e249ee14bd16baf080489a107bbfdbf5 Mon Sep 17 00:00:00 2001 From: yihellen <42916179+yihellen@users.noreply.github.com> Date: Thu, 26 May 2022 07:21:59 -0700 Subject: Add automaton parser (#1426) * have compilable program * enable read in file * add hashmap usage * add build hashmap; WIP; test if constructed correctly tomorrow * add testcase to test hashmap * add sorted symbols list * build symbols dictionary * clean up DEBUG * successfully find automaton path * fix all memory leaks * test if automaton same with example * able to iterate through files in a folder * finish testing on one random queue wip - change macro values - add bound checking * add bound checking to program length * add bound checking to program walk length * add boundary check to terminal number, terminal lengths and program length * commit test makefile * add makefile * able to add seeds to gramatron * remove useless argument in automaton_parser * add automaton parser to gramfuzz * change build * revert test.c to original state * add makefile to test.c for testing --- custom_mutators/gramatron/automaton-parser.c | 367 +++++++++++++++++++++ custom_mutators/gramatron/automaton-parser.h | 74 +++++ .../gramatron/build_gramatron_mutator.sh | 4 +- custom_mutators/gramatron/gramfuzz.c | 41 ++- custom_mutators/gramatron/hashmap.c | 5 +- custom_mutators/gramatron/testMakefile.mk | 2 + .../grammar_mutator/build_grammar_mutator.sh | 2 +- 7 files changed, 486 insertions(+), 9 deletions(-) create mode 100644 custom_mutators/gramatron/automaton-parser.c create mode 100644 custom_mutators/gramatron/automaton-parser.h create mode 100644 custom_mutators/gramatron/testMakefile.mk diff --git a/custom_mutators/gramatron/automaton-parser.c b/custom_mutators/gramatron/automaton-parser.c new file mode 100644 index 00000000..3265e0cf --- /dev/null +++ b/custom_mutators/gramatron/automaton-parser.c @@ -0,0 +1,367 @@ +#include "afl-fuzz.h" +#include "automaton-parser.h" + +int free_terminal_arr(any_t placeholder, any_t item) { + struct terminal_arr* tmp = item; + free(tmp->start); + free(tmp); + return MAP_OK; +} + +int compare_two_symbols(const void * a, const void * b) { + char* a_char = *(char **)a; + char* b_char = *(char **)b; + size_t fa = strlen(a_char); + size_t fb = strlen(b_char); + if (fa > fb) return -1; + else if (fa == fb) return 0; + else return 1; + +} + +// TODO: create a map +// key: first character of a symbol, value: a list of symbols that starts with key, the list is sorted in descending order of the symbol lengths +map_t create_first_char_to_symbols_hashmap(struct symbols_arr *symbols, struct symbols_arr *first_chars) { + map_t char_to_symbols = hashmap_new(); + // TODO: free the allocated map + // sort the symbol_dict in descending order of the symbol lengths + qsort(symbols->symbols_arr, symbols->len, sizeof(char*), compare_two_symbols); + #ifdef DEBUG + printf("------ print after sort ------\n"); + print_symbols_arr(symbols); + #endif + size_t i; + int r; // response from hashmap get and put + for (i = 0; i < symbols->len; i++) { + char* symbol_curr = symbols->symbols_arr[i]; + // get first character from symbol_curr + char first_character[2]; + first_character[0] = symbol_curr[0]; + first_character[1] = '\0'; + #ifdef DEBUG + printf("****** Current symbol is %s, its first character is %s ******\n", symbol_curr, first_character); + #endif + // key would be the first character of symbol_curr + // the value would be an array of chars + struct symbols_arr* associated_symbols; + r = hashmap_get(char_to_symbols, first_character, (any_t*)&associated_symbols); + if (!r) { + // append current symbol to existing array + #ifdef DEBUG + printf("****** First character %s is already in hashmap ******\n", first_character); + #endif + if(!add_element_to_symbols_arr(associated_symbols, symbol_curr, strlen(symbol_curr) + 1)) { + free_hashmap(char_to_symbols, &free_array_of_chars); + return NULL; + } + } + else { + // start a new symbols_arr + #ifdef DEBUG + printf("****** First character %s is not in hashmap ******\n", first_character); + #endif + struct symbols_arr* new_associated_symbols = create_array_of_chars(); + strncpy(first_chars->symbols_arr[first_chars->len], first_character, 2); // 2 because one character plus the NULL byte + add_element_to_symbols_arr(new_associated_symbols, symbol_curr, strlen(symbol_curr) + 1); + r = hashmap_put(char_to_symbols, first_chars->symbols_arr[first_chars->len], new_associated_symbols); + first_chars->len++; + #ifdef DEBUG + if (r) { + printf("hashmap put failed\n"); + } + else { + printf("hashmap put succeeded\n"); + } + #endif + } + } + printf("****** Testing ******\n"); + struct symbols_arr* tmp_arr; + char str[] = "i"; + int t = hashmap_get(char_to_symbols, str, (any_t *)&tmp_arr); + if (!t) + print_symbols_arr(tmp_arr); + return char_to_symbols; +} + +struct symbols_arr* create_array_of_chars() { + struct symbols_arr* ret = (struct symbols_arr*)malloc(sizeof(struct symbols_arr)); + ret->len = 0; + ret->symbols_arr = (char **)malloc(MAX_TERMINAL_NUMS * sizeof(char*)); + size_t i; + for (i = 0; i < MAX_TERMINAL_NUMS; i++) { + ret->symbols_arr[i] = (char *)calloc(MAX_TERMINAL_LENGTH, sizeof(char)); + } + return ret; +} + +// map a symbol to a list of (state, trigger_idx) +map_t create_pda_hashmap(state* pda, struct symbols_arr* symbols_arr) { + int state_idx, trigger_idx, r; // r is the return result for hashmap operation + map_t m = hashmap_new(); + // iterate over pda + for (state_idx = 0; state_idx < numstates; state_idx++) { + #ifdef DEBUG + printf("------ The state idx is %d ------\n", state_idx); + #endif + if (state_idx == final_state) continue; + state* state_curr = pda + state_idx; + for (trigger_idx = 0; trigger_idx < state_curr->trigger_len; trigger_idx++) { + #ifdef DEBUG + printf("------ The trigger idx is %d ------\n", trigger_idx); + #endif + trigger* trigger_curr = state_curr->ptr + trigger_idx; + char* symbol_curr = trigger_curr->term; + size_t symbol_len = trigger_curr->term_len; + struct terminal_arr* terminal_arr_curr; + r = hashmap_get(m, symbol_curr, (any_t*)&terminal_arr_curr); + if (r) { + // the symbol is not in the map + if (!add_element_to_symbols_arr(symbols_arr, symbol_curr, symbol_len+1)) { + // the number of symbols exceed maximual number + free_hashmap(m, &free_terminal_arr); + return NULL; + } + #ifdef DEBUG + printf("Symbol %s is not in map\n", symbol_curr); + #endif + struct terminal_arr* new_terminal_arr = (struct terminal_arr*)malloc(sizeof(struct terminal_arr)); + new_terminal_arr->start = (struct terminal_meta*)calloc(numstates, sizeof(struct terminal_meta)); + #ifdef DEBUG + printf("allocate new memory address %p\n", new_terminal_arr->start); + #endif + new_terminal_arr->start->state_name = state_idx; + new_terminal_arr->start->dest = trigger_curr->dest; + new_terminal_arr->start->trigger_idx = trigger_idx; + new_terminal_arr->len = 1; + #ifdef DEBUG + printf("Symbol %s is included in %zu edges\n", symbol_curr, new_terminal_arr->len); + #endif + r = hashmap_put(m, symbol_curr, new_terminal_arr); + #ifdef DEBUG + if (r) { + printf("hashmap put failed\n"); + } + else { + printf("hashmap put succeeded\n"); + } + #endif + // if symbol not already in map, it's not in symbol_dict, simply add the symbol to the array + // TODO: need to initialize symbol dict (calloc) + } + else { + // the symbol is already in map + // append to terminal array + // no need to touch start + #ifdef DEBUG + printf("Symbol %s is in map\n", symbol_curr); + #endif + struct terminal_meta* modify = terminal_arr_curr->start + terminal_arr_curr->len; + modify->state_name = state_idx; + modify->trigger_idx = trigger_idx; + modify->dest = trigger_curr->dest; + terminal_arr_curr->len++; + #ifdef DEBUG + printf("Symbol %s is included in %zu edges\n", symbol_curr, terminal_arr_curr->len); + #endif + // if symbol already in map, it's already in symbol_dict as well, no work needs to be done + } + + } + } + return m; +} + +void print_symbols_arr(struct symbols_arr* arr) { + size_t i; + printf("("); + for (i = 0; i < arr->len; i++) { + printf("%s", arr->symbols_arr[i]); + if (i != arr->len - 1) printf(","); + } + printf(")\n"); +} + +void free_hashmap(map_t m, int (*f)(any_t, any_t)) { + if (!m) { + printf("m map is empty\n"); + return; + } + int r = hashmap_iterate(m, f, NULL); + #ifdef DEBUG + if (!r) printf("free hashmap items successfully!\n"); + else printf("free hashmap items failed"); + #endif + hashmap_free(m); +} + +int free_array_of_chars(any_t placeholder, any_t item) { + if (!item) { + printf("item is empty\n"); + return MAP_MISSING; + } + struct symbols_arr* arr = item; + size_t i; + for (i = 0; i < MAX_TERMINAL_NUMS; i++) { + free(arr->symbols_arr[i]); + } + free(arr->symbols_arr); + free(arr); + return MAP_OK; +} + +void free_pda(state* pda) { + if (!pda) { + printf("pda is null\n"); + return; + } + size_t i, j; + for (i = 0; i < numstates; i++) { + state* state_curr = pda + i; + for (j = 0; j < state_curr->trigger_len; j++) { + trigger* trigger_curr = state_curr->ptr + j; + free(trigger_curr->id); + free(trigger_curr->term); + } + free(state_curr->ptr); + } + free(pda); +} + +int dfs(struct terminal_arr** tmp, const char* program, const size_t program_length, struct terminal_arr** res, size_t idx, int curr_state) { + if (*res) return 1; // 1 means successfully found a path + if (idx == program_length) { + // test if the last terminal points to the final state + if (curr_state != final_state) return 0; + *res = *tmp; + return 1; + } + if ((*tmp)->len == MAX_PROGRAM_WALK_LENGTH) { + printf("Reached maximum program walk length\n"); + return 0; + } + char first_char[2]; + first_char[0] = program[idx]; // first character of program + first_char[1] = '\0'; + int r; + struct symbols_arr* matching_symbols; + r = hashmap_get(first_char_to_symbols_map, first_char, (any_t *)&matching_symbols); + if (r) { + printf("No symbols match the current character, abort!"); // hopefully won't reach this state + return 0; + } + size_t i; + bool matched = false; + for (i = 0; i < matching_symbols->len; i++) { + if (matched) break; + char *matching_symbol = matching_symbols->symbols_arr[i]; + if (!strncmp(matching_symbol, program + idx, strlen(matching_symbol))) { + // there is a match + matched = true; + // find the possible paths of that symbol + struct terminal_arr* ta; + int r2 = hashmap_get(pda_map, matching_symbol, (any_t *)&ta); + if (!r2) { + // the terminal is found in the dictionary + size_t j; + for (j = 0; j < ta->len; j++) { + int state_name = (ta->start + j)->state_name; + if (state_name != curr_state) continue; + size_t trigger_idx = (ta->start + j)->trigger_idx; + int dest = (ta->start + j)->dest; + (*tmp)->start[(*tmp)->len].state_name = state_name; + (*tmp)->start[(*tmp)->len].trigger_idx = trigger_idx; + (*tmp)->start[(*tmp)->len].dest = dest; + (*tmp)->len++; + if (dfs(tmp, program, program_length, res, idx + strlen(matching_symbol), dest)) return 1; + (*tmp)->len--; + } + } + else { + printf("No path goes out of this symbol, abort!"); // hopefully won't reach this state + return 0; + } + } + } + return 0; + /* + 1. First extract the first character of the current program + 2. Match the possible symbols of that program + 3. Find the possible paths of that symbol + 4. Add to temporary terminal array + 5. Recursion + 6. Pop the path from the terminal array + 7. - If idx reaches end of program, set tmp to res + - If idx is not at the end and nothing matches, the current path is not working, simply return 0 + */ +} + +Array* constructArray(struct terminal_arr* terminal_arr, state* pda) { + Array * res = (Array *)calloc(1, sizeof(Array)); + initArray(res, INIT_SIZE); + size_t i; + for (i = 0; i < terminal_arr->len; i ++) { + struct terminal_meta* curr = terminal_arr->start + i; + int state_name = curr->state_name; + int trigger_idx = curr->trigger_idx; + // get the symbol from pda + state* state_curr = pda + state_name; + trigger* trigger_curr = state_curr->ptr + trigger_idx; + char *symbol_curr = trigger_curr->term; + size_t symbol_curr_len = trigger_curr->term_len; + insertArray(res, state_name, symbol_curr, symbol_curr_len, trigger_idx); + } + return res; +} + +Array* automaton_parser(const uint8_t *seed_fn) { + Array* parsed_res = NULL; + FILE* ptr; + ptr = fopen(seed_fn, "r"); + if (ptr == NULL) { + printf("file can't be opened \n"); + fclose(ptr); + return NULL; + } + char ch; + char program[MAX_PROGRAM_LENGTH]; + int i = 0; + bool program_too_long = false; + do { + if (i == MAX_PROGRAM_LENGTH) { + // the maximum program length is reached + printf("maximum program length is reached, give up the current seed\n"); + program_too_long = true; + break; + } + ch = fgetc(ptr); + program[i] = ch; + i ++; + } while (ch != EOF); + program[i-1] = '\0'; + fclose(ptr); + if ((i == 1 && program[0] == '\0') || program_too_long) return NULL; + struct terminal_arr* arr_holder; + struct terminal_arr* dfs_res = NULL; + arr_holder = (struct terminal_arr*)calloc(1, sizeof(struct terminal_arr)); + arr_holder->start = (struct terminal_meta*)calloc(MAX_PROGRAM_WALK_LENGTH, sizeof(struct terminal_meta)); + int dfs_success = dfs(&arr_holder, program, strlen(program), &dfs_res, 0, init_state); + // printf("*** return value %d *** \n", dfs_success); + if (dfs_success) { + parsed_res = constructArray(dfs_res, pda); + } + free(arr_holder->start); + free(arr_holder); + return parsed_res; +} + +// return 0 if fails +// return 1 if succeeds +int add_element_to_symbols_arr(struct symbols_arr* symbols_arr, char* symbol, size_t symbol_len) { + if (symbols_arr->len >= MAX_TERMINAL_NUMS || symbol_len >= MAX_TERMINAL_LENGTH) { + return 0; + } + strncpy(symbols_arr->symbols_arr[symbols_arr->len], symbol, symbol_len); + symbols_arr->len++; + return 1; +} \ No newline at end of file diff --git a/custom_mutators/gramatron/automaton-parser.h b/custom_mutators/gramatron/automaton-parser.h new file mode 100644 index 00000000..d67a1679 --- /dev/null +++ b/custom_mutators/gramatron/automaton-parser.h @@ -0,0 +1,74 @@ +#ifndef _AUTOMATON_PARSER_H +#define _AUTOMATON_PARSER_H + +#define NUMINPUTS 500 +#define MAX_PROGRAM_LENGTH 20000 +#define MAX_PROGRAM_WALK_LENGTH 5000 +#define MAX_TERMINAL_NUMS 5000 +#define MAX_TERMINAL_LENGTH 1000 +#define MAX_PROGRAM_NAME_LENGTH 5000 + +#include "gramfuzz.h" + +// represents an edge in the FSA +struct terminal_meta { + + int state_name; + int trigger_idx; + int dest; + +} ; + +// represents a set of edges +struct terminal_arr { + + struct terminal_meta* start; + size_t len; + +} ; + +// essentially a string array +struct symbols_arr { + char** symbols_arr; + size_t len; +} ; + +struct symbols_arr* symbols; // symbols contain all the symbols in the language +map_t pda_map; // a map that maps each symbol in the language to a set of edges +struct symbols_arr* first_chars; // an array of first characters, only temperary array +map_t first_char_to_symbols_map; // a map that maps each first character to a set of symbols (the symbols are sorted in descending order) + + + +// freeing terminal arrays +int free_terminal_arr(any_t placeholder, any_t item); + +// return a map that maps each symbol in the language to a set of edges +// populate symbols_arr with all the symbols in the language +map_t create_pda_hashmap(state* pda, struct symbols_arr* symbols_arr); + +// print the string array +void print_symbols_arr(struct symbols_arr* arr); + +// free hashmap +// the function pointer contains function to free the values in the hashmap +void free_hashmap(map_t m, int (*f)(any_t, any_t)); + +// free string array +int free_array_of_chars(any_t placeholder, any_t item); + +// free the pda +void free_pda(state* pda); + +// create a string array +struct symbols_arr* create_array_of_chars(); + +map_t create_first_char_to_symbols_hashmap(struct symbols_arr *symbols, struct symbols_arr *first_chars); + +// return the automaton represented by the seed +Array* automaton_parser(const uint8_t *seed_fn); + +int add_element_to_symbols_arr(struct symbols_arr* symbols_arr, char* symbol, size_t symbol_len); + + +#endif \ No newline at end of file diff --git a/custom_mutators/gramatron/build_gramatron_mutator.sh b/custom_mutators/gramatron/build_gramatron_mutator.sh index 9952e7f5..0638e3b2 100755 --- a/custom_mutators/gramatron/build_gramatron_mutator.sh +++ b/custom_mutators/gramatron/build_gramatron_mutator.sh @@ -125,7 +125,7 @@ else } fi -test -d json-c/.git || { echo "[-] not checked out, please install git or check your internet connection." ; exit 1 ; } +test -f json-c/.git || { echo "[-] not checked out, please install git or check your internet connection." ; exit 1 ; } echo "[+] Got json-c." test -e json-c/.libs/libjson-c.a || { @@ -144,6 +144,6 @@ echo echo echo "[+] Json-c successfully prepared!" echo "[+] Builing gramatron now." -$CC -O3 -g -fPIC -Wno-unused-result -Wl,--allow-multiple-definition -I../../include -o gramatron.so -shared -I. -I/prg/dev/include gramfuzz.c gramfuzz-helpers.c gramfuzz-mutators.c gramfuzz-util.c hashmap.c ../../src/afl-performance.o json-c/.libs/libjson-c.a || exit 1 +$CC -O3 -g -fPIC -Wno-unused-result -Wl,--allow-multiple-definition -I../../include -o gramatron.so -shared -I. -I/prg/dev/include gramfuzz.c gramfuzz-helpers.c gramfuzz-mutators.c gramfuzz-util.c hashmap.c automaton-parser.c ../../src/afl-performance.o json-c/.libs/libjson-c.a || exit 1 echo echo "[+] gramatron successfully built!" diff --git a/custom_mutators/gramatron/gramfuzz.c b/custom_mutators/gramatron/gramfuzz.c index 9c9dbb43..ccdbbe60 100644 --- a/custom_mutators/gramatron/gramfuzz.c +++ b/custom_mutators/gramatron/gramfuzz.c @@ -9,6 +9,7 @@ #include "afl-fuzz.h" #include "gramfuzz.h" +#include "automaton-parser.h" #define MUTATORS 4 // Specify the total number of mutators @@ -163,6 +164,11 @@ my_mutator_t *afl_custom_init(afl_state_t *afl, unsigned int seed) { if (automaton_file) { pda = create_pda(automaton_file); + symbols = create_array_of_chars(); + pda_map = create_pda_hashmap((struct state*)pda, symbols); + print_symbols_arr(symbols); + first_chars = create_array_of_chars(); + first_char_to_symbols_map = create_first_char_to_symbols_hashmap(symbols, first_chars); } else { @@ -281,12 +287,25 @@ u8 afl_custom_queue_new_entry(my_mutator_t * data, // filename_new_queue,filename_orig_queue,automaton_fn); if (filename_orig_queue) { - - write_input(data->mutated_walk, automaton_fn); + if (data->mutated_walk) { + write_input(data->mutated_walk, automaton_fn); + } + else { + Array* parsed_walk = automaton_parser(filename_new_queue); + if (!parsed_walk) PFATAL("Parser unsuccessful on %s", filename_new_queue); + write_input(parsed_walk, automaton_fn); + free(parsed_walk->start); + free(parsed_walk); + } } else { - new_input = gen_input(pda, NULL); + // TODO: try to parse the input seeds here, if they can be parsed, then generate the corresponding automaton file + // if not, then generate a new input + new_input = automaton_parser(filename_new_queue); + if (new_input == NULL) { + new_input = gen_input(pda, NULL); + } write_input(new_input, automaton_fn); // Update the placeholder file @@ -328,6 +347,16 @@ uint8_t afl_custom_queue_get(my_mutator_t *data, const uint8_t *filename) { // get the filename u8 * automaton_fn = alloc_printf("%s.aut", filename); + // find the automaton file, if the automaton file cannot be found, do not fuzz the current entry on the queue + FILE *fp; + fp = fopen(automaton_fn, "rb"); + if (fp == NULL) { + + printf("File '%s' does not exist, exiting. Would not fuzz current entry on the queue\n", automaton_fn); + return 0; + + } + IdxMap_new *statemap_ptr; terminal * term_ptr; int state; @@ -424,6 +453,10 @@ void afl_custom_deinit(my_mutator_t *data) { free(data->mutator_buf); free(data); - + free_hashmap(pda_map, &free_terminal_arr); + free_hashmap(first_char_to_symbols_map, &free_array_of_chars); + free_pda(pda); + free_array_of_chars(NULL, symbols); // free the array of symbols + free_array_of_chars(NULL, first_chars); } diff --git a/custom_mutators/gramatron/hashmap.c b/custom_mutators/gramatron/hashmap.c index 09715b87..4f97e085 100644 --- a/custom_mutators/gramatron/hashmap.c +++ b/custom_mutators/gramatron/hashmap.c @@ -151,7 +151,7 @@ static unsigned long crc32_tab[] = { /* Return a 32-bit CRC of the contents of the buffer. */ -unsigned long crc32(const unsigned char *s, unsigned int len) { +unsigned long custom_crc32(const unsigned char *s, unsigned int len) { unsigned int i; unsigned long crc32val; @@ -171,8 +171,9 @@ unsigned long crc32(const unsigned char *s, unsigned int len) { * Hashing function for a string */ unsigned int hashmap_hash_int(hashmap_map *m, char *keystring) { + unsigned int keystring_len = strlen(keystring); - unsigned long key = crc32((unsigned char *)(keystring), strlen(keystring)); + unsigned long key = custom_crc32((unsigned char *)(keystring), keystring_len); /* Robert Jenkins' 32 bit Mix Function */ key += (key << 12); diff --git a/custom_mutators/gramatron/testMakefile.mk b/custom_mutators/gramatron/testMakefile.mk new file mode 100644 index 00000000..0b2c6236 --- /dev/null +++ b/custom_mutators/gramatron/testMakefile.mk @@ -0,0 +1,2 @@ +test: test.c + gcc -g -fPIC -Wno-unused-result -Wl,--allow-multiple-definition -I../../include -o test -I. -I/prg/dev/include test.c gramfuzz-helpers.c gramfuzz-mutators.c gramfuzz-util.c hashmap.c ../../src/afl-performance.o json-c/.libs/libjson-c.a \ No newline at end of file diff --git a/custom_mutators/grammar_mutator/build_grammar_mutator.sh b/custom_mutators/grammar_mutator/build_grammar_mutator.sh index 15b8b1db..e8594ba3 100755 --- a/custom_mutators/grammar_mutator/build_grammar_mutator.sh +++ b/custom_mutators/grammar_mutator/build_grammar_mutator.sh @@ -119,7 +119,7 @@ else } fi -test -d grammar_mutator/.git || { echo "[-] not checked out, please install git or check your internet connection." ; exit 1 ; } +test -f grammar_mutator/.git || { echo "[-] not checked out, please install git or check your internet connection." ; exit 1 ; } echo "[+] Got grammar mutator." cd "grammar_mutator" || exit 1 -- cgit 1.4.1 From c96238d85f4a784402db6cbf16630b977617eb1a Mon Sep 17 00:00:00 2001 From: Daniil Kuts <13482580+apach301@users.noreply.github.com> Date: Fri, 27 May 2022 13:52:31 +0300 Subject: Add AFL_SYNC_TIME variable for synchronization time tuning (#1425) * Add AFL_SYNC_TIME variable for synchronization time tuning * Documentation for AFL_SYNC_TIME variable --- docs/env_variables.md | 4 ++++ include/afl-fuzz.h | 3 ++- include/envs.h | 1 + src/afl-fuzz-state.c | 12 ++++++++++++ src/afl-fuzz.c | 5 +++-- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/env_variables.md b/docs/env_variables.md index fe9c6e07..3c69c0b6 100644 --- a/docs/env_variables.md +++ b/docs/env_variables.md @@ -517,6 +517,10 @@ checks or alter some of the more exotic semantics of the tool: (empty/non present) will add no tags to the metrics. For more information, see [rpc_statsd.md](rpc_statsd.md). + - `AFL_SYNC_TIME` allows you to specify a different minimal time (in minutes) + between fuzzing instances synchronization. Default sync time is 30 minutes, + note that time is halfed for -M main nodes. + - Setting `AFL_TARGET_ENV` causes AFL++ to set extra environment variables for the target binary. Example: `AFL_TARGET_ENV="VAR1=1 VAR2='a b c'" afl-fuzz ... `. This exists mostly for things like `LD_LIBRARY_PATH` but it would diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h index 9992e841..24af426f 100644 --- a/include/afl-fuzz.h +++ b/include/afl-fuzz.h @@ -577,7 +577,8 @@ typedef struct afl_state { last_find_time, /* Time for most recent path (ms) */ last_crash_time, /* Time for most recent crash (ms) */ last_hang_time, /* Time for most recent hang (ms) */ - exit_on_time; /* Delay to exit if no new paths */ + exit_on_time, /* Delay to exit if no new paths */ + sync_time; /* Sync time (ms) */ u32 slowest_exec_ms, /* Slowest testcase non hang in ms */ subseq_tmouts; /* Number of timeouts in a row */ diff --git a/include/envs.h b/include/envs.h index 25b792fa..f4cccc96 100644 --- a/include/envs.h +++ b/include/envs.h @@ -206,6 +206,7 @@ static char *afl_environment_variables[] = { "AFL_STATSD_HOST", "AFL_STATSD_PORT", "AFL_STATSD_TAGS_FLAVOR", + "AFL_SYNC_TIME", "AFL_TESTCACHE_SIZE", "AFL_TESTCACHE_ENTRIES", "AFL_TMIN_EXACT", diff --git a/src/afl-fuzz-state.c b/src/afl-fuzz-state.c index 98217438..cbe32c75 100644 --- a/src/afl-fuzz-state.c +++ b/src/afl-fuzz-state.c @@ -101,6 +101,7 @@ void afl_state_init(afl_state_t *afl, uint32_t map_size) { afl->stats_update_freq = 1; afl->stats_avg_exec = 0; afl->skip_deterministic = 1; + afl->sync_time = SYNC_TIME; afl->cmplog_lvl = 2; afl->min_length = 1; afl->max_length = MAX_FILE; @@ -519,6 +520,17 @@ void read_afl_environment(afl_state_t *afl, char **envp) { } + } else if (!strncmp(env, "AFL_SYNC_TIME", + + afl_environment_variable_len)) { + + int time = atoi((u8 *)get_afl_env(afl_environment_variables[i])); + if (time > 0) { + afl->sync_time = time * (60 * 1000LL); + } else { + WARNF("incorrect value for AFL_SYNC_TIME environment variable, " + "used default value %lld instead.", afl->sync_time / 60 / 1000); + } } } else { diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c index c5ab364a..7c33ba29 100644 --- a/src/afl-fuzz.c +++ b/src/afl-fuzz.c @@ -295,6 +295,7 @@ static void usage(u8 *argv0, int more_help) { "AFL_STATSD_TAGS_FLAVOR: set statsd tags format (default: disable tags)\n" " Supported formats are: 'dogstatsd', 'librato',\n" " 'signalfx' and 'influxdb'\n" + "AFL_SYNC_TIME: sync time between fuzzing instances (in minutes)\n" "AFL_TESTCACHE_SIZE: use a cache for testcases, improves performance (in MB)\n" "AFL_TMPDIR: directory to use for input file generation (ramdisk recommended)\n" "AFL_EARLY_FORKSERVER: force an early forkserver in an afl-clang-fast/\n" @@ -2511,7 +2512,7 @@ int main(int argc, char **argv_orig, char **envp) { if (unlikely(afl->is_main_node)) { if (unlikely(get_cur_time() > - (SYNC_TIME >> 1) + afl->last_sync_time)) { + (afl->sync_time >> 1) + afl->last_sync_time)) { if (!(sync_interval_cnt++ % (SYNC_INTERVAL / 3))) { @@ -2523,7 +2524,7 @@ int main(int argc, char **argv_orig, char **envp) { } else { - if (unlikely(get_cur_time() > SYNC_TIME + afl->last_sync_time)) { + if (unlikely(get_cur_time() > afl->sync_time + afl->last_sync_time)) { if (!(sync_interval_cnt++ % SYNC_INTERVAL)) { sync_fuzzers(afl); } -- cgit 1.4.1 From 1441503c4328735ce78367b24f71a6f999760113 Mon Sep 17 00:00:00 2001 From: hexcoder- Date: Fri, 27 May 2022 15:26:24 +0200 Subject: afl-cmin: avoid messages with \r when redirection is used --- afl-cmin | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/afl-cmin b/afl-cmin index 853c9398..71723c70 100755 --- a/afl-cmin +++ b/afl-cmin @@ -135,6 +135,12 @@ function exists_and_is_executable(binarypath) { } BEGIN { + if (0 != system( "test -t 1")) { + redirected = 1 + } else { + redirected = 0 + } + print "corpus minimization tool for afl++ (awk version)\n" # defaults @@ -463,7 +469,8 @@ BEGIN { while (cur < in_count) { fn = infilesSmallToBig[cur] ++cur - printf "\r Processing file "cur"/"in_count + if (redirected == 0) { printf "\r Processing file "cur"/"in_count } + else { print " Processing file "cur"/"in_count } # create path for the trace file from afl-showmap tracefile_path = trace_dir"/"fn # gather all keys, and count them @@ -502,7 +509,9 @@ BEGIN { key = field[nrFields] ++tcnt; - printf "\r Processing tuple "tcnt"/"tuple_count" with count "key_count[key]"..." + if (redirected == 0) { printf "\r Processing tuple "tcnt"/"tuple_count" with count "key_count[key]"..." } + else { print " Processing tuple "tcnt"/"tuple_count" with count "key_count[key]"..." } + if (key in keyAlreadyKnown) { continue } -- cgit 1.4.1 From 066d65d8469ca504ab86771bd8e5e608efec9517 Mon Sep 17 00:00:00 2001 From: Luca Di Bartolomeo Date: Fri, 27 May 2022 17:55:21 +0200 Subject: Fix wrong memchr size in android (#1429) Need to fix this otherwise ASAN will always complain about heap buffer overflows and refuse to run. Co-authored-by: van Hauser --- src/afl-fuzz-stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/afl-fuzz-stats.c b/src/afl-fuzz-stats.c index 5b237748..3e034b83 100644 --- a/src/afl-fuzz-stats.c +++ b/src/afl-fuzz-stats.c @@ -59,7 +59,7 @@ void write_setup_file(afl_state_t *afl, u32 argc, char **argv) { if (i) fprintf(f, " "); #ifdef __ANDROID__ - if (memchr(argv[i], '\'', sizeof(argv[i]))) { + if (memchr(argv[i], '\'', strlen(argv[i]))) { #else if (index(argv[i], '\'')) { -- cgit 1.4.1 From 50c6031cc3350b3fea486774ddef89eaf2cab5c3 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Tue, 31 May 2022 09:24:28 +0200 Subject: remove optimin --- .gitmodules | 3 - docs/Changelog.md | 3 + utils/README.md | 2 - utils/optimin/.gitignore | 11 - utils/optimin/CMakeLists.txt | 22 -- utils/optimin/EVALMAXSAT_VERSION | 1 - utils/optimin/EvalMaxSAT | 1 - utils/optimin/README.md | 94 ------ utils/optimin/build_optimin.sh | 131 -------- utils/optimin/src/CMakeLists.txt | 13 - utils/optimin/src/OptiMin.cpp | 702 --------------------------------------- 11 files changed, 3 insertions(+), 980 deletions(-) delete mode 100644 utils/optimin/.gitignore delete mode 100644 utils/optimin/CMakeLists.txt delete mode 100644 utils/optimin/EVALMAXSAT_VERSION delete mode 160000 utils/optimin/EvalMaxSAT delete mode 100644 utils/optimin/README.md delete mode 100755 utils/optimin/build_optimin.sh delete mode 100644 utils/optimin/src/CMakeLists.txt delete mode 100644 utils/optimin/src/OptiMin.cpp diff --git a/.gitmodules b/.gitmodules index 8ba1c39d..18fda27e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,9 +10,6 @@ [submodule "custom_mutators/gramatron/json-c"] path = custom_mutators/gramatron/json-c url = https://github.com/json-c/json-c -[submodule "utils/optimin/EvalMaxSAT"] - path = utils/optimin/EvalMaxSAT - url = https://github.com/FlorentAvellaneda/EvalMaxSAT [submodule "coresight_mode/patchelf"] path = coresight_mode/patchelf url = https://github.com/NixOS/patchelf.git diff --git a/docs/Changelog.md b/docs/Changelog.md index b18bf30f..6269e3b1 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -41,6 +41,9 @@ sending a mail to . - update to new frida release, handles now c++ throw/catch - unicorn_mode: - update unicorn engine, fix C example + - utils: + - removed optimin because it looses coverage due a bug and is + unmaintained :-( ### Version ++4.00c (release) diff --git a/utils/README.md b/utils/README.md index debc86e8..62d79193 100644 --- a/utils/README.md +++ b/utils/README.md @@ -56,8 +56,6 @@ Here's a quick overview of the stuff you can find in this directory: - libpng_no_checksum - a sample patch for removing CRC checks in libpng. - - optimin - An optimal corpus minimizer. - - persistent_mode - an example of how to use the LLVM persistent process mode to speed up certain fuzzing jobs. diff --git a/utils/optimin/.gitignore b/utils/optimin/.gitignore deleted file mode 100644 index 46f42f8f..00000000 --- a/utils/optimin/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -CMakeLists.txt.user -CMakeCache.txt -CMakeFiles -CMakeScripts -Testing -Makefile -cmake_install.cmake -install_manifest.txt -compile_commands.json -CTestTestfile.cmake -_deps diff --git a/utils/optimin/CMakeLists.txt b/utils/optimin/CMakeLists.txt deleted file mode 100644 index b45dd004..00000000 --- a/utils/optimin/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 3.10) - -project(optimin - LANGUAGES CXX - DESCRIPTION "MaxSAT-based fuzzing corpus minimizer" -) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") - -# Add LLVM -find_package(LLVM REQUIRED CONFIG) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") - -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS} -DNDEBUG) - -add_subdirectory(EvalMaxSAT) -add_subdirectory(src) diff --git a/utils/optimin/EVALMAXSAT_VERSION b/utils/optimin/EVALMAXSAT_VERSION deleted file mode 100644 index d836ff1c..00000000 --- a/utils/optimin/EVALMAXSAT_VERSION +++ /dev/null @@ -1 +0,0 @@ -440bf90edf88f6ab940934129e3c5b3b93764295 diff --git a/utils/optimin/EvalMaxSAT b/utils/optimin/EvalMaxSAT deleted file mode 160000 index 440bf90e..00000000 --- a/utils/optimin/EvalMaxSAT +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 440bf90edf88f6ab940934129e3c5b3b93764295 diff --git a/utils/optimin/README.md b/utils/optimin/README.md deleted file mode 100644 index 340022b8..00000000 --- a/utils/optimin/README.md +++ /dev/null @@ -1,94 +0,0 @@ -# OptiMin - -OptiMin is a corpus minimizer that uses a -[MaxSAT](https://en.wikipedia.org/wiki/Maximum_satisfiability_problem) solver -to identify a subset of functionally distinct files that exercise different code -paths in a target program. - -Unlike most corpus minimizers, such as `afl-cmin`, OptiMin does not rely on -heuristic and/or greedy algorithms to identify these functionally distinct -files. This means that minimized corpora are generally much smaller than those -produced by other tools. - -## Building - -To build the `optimin` just execute the `build_optimin.sh` script. - -## Running - -Running `optimin` is the same as running `afl-cmin`: - -``` -./optimin -h -OVERVIEW: Optimal corpus minimizer -USAGE: optimin [options] [target args...] - -OPTIONS: - -Color Options: - - --color - Use colors in output (default=autodetect) - -General options: - - -C - Keep crashing inputs, reject everything else - -O - Use binary-only instrumentation (FRIDA mode) - -Q - Use binary-only instrumentation (QEMU mode) - -U - Use unicorn-based instrumentation (unicorn mode) - -f - Include edge hit counts - -i dir - Input directory - -m megs - Memory limit for child process (default=none) - -o dir - Output directory - -p - Display progress bar - -t msec - Run time limit for child process (default=5000) - -w csv - Weights file - -Generic Options: - - --help - Display available options (--help-hidden for more) - --help-list - Display list of available options (--help-list-hidden for more) - --version - Display the version of this program -``` - -Example: `optimin -i files -o seeds -- ./target @@` - -### Weighted Minimizations - -OptiMin allows for weighted minimizations. For examples, seeds can be weighted -by file size (or execution time), thus preferencing the selection of smaller (or -faster) seeds. - -To perform a weighted minimization, supply a CSV file with the `-w` option. This -CSV file is formatted as follows: - -``` -SEED_1,WEIGHT_1 -SEED_2,WEIGHT_2 -... -SEED_N,WEIGHT_N -``` - -Where `SEED_N` is the file name (**not** path) of a seed in the input directory, -and `WEIGHT_N` is an integer weight. - -## Further Details and Citation - -For more details, see the paper -[Seed Selection for Successful Fuzzing](https://dl.acm.org/doi/10.1145/3460319.3464795). -If you use OptiMin in your research, please cite this paper. - -BibTeX: - -```bibtex -@inproceedings{Herrera:2021:FuzzSeedSelection, - author = {Adrian Herrera and Hendra Gunadi and Shane Magrath and Michael Norrish and Mathias Payer and Antony L. Hosking}, - title = {Seed Selection for Successful Fuzzing}, - booktitle = {30th ACM SIGSOFT International Symposium on Software Testing and Analysis}, - series = {ISSTA}, - year = {2021}, - pages = {230--243}, - numpages = {14}, - location = {Virtual, Denmark}, - publisher = {Association for Computing Machinery}, -} -``` \ No newline at end of file diff --git a/utils/optimin/build_optimin.sh b/utils/optimin/build_optimin.sh deleted file mode 100755 index aee5d0c3..00000000 --- a/utils/optimin/build_optimin.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/sh -# -# american fuzzy lop++ - optimin build script -# ------------------------------------------------ -# -# Originally written by Nathan Voss -# -# Adapted from code by Andrew Griffiths and -# Michal Zalewski -# -# Adapted for AFLplusplus by Dominik Maier -# -# Copyright 2017 Battelle Memorial Institute. All rights reserved. -# Copyright 2019-2022 AFLplusplus Project. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# This script builds the OptiMin corpus minimizer. - -EVALMAXSAT_VERSION="$(cat ./EVALMAXSAT_VERSION)" -EVALMAXSAT_REPO="https://github.com/FlorentAvellaneda/EvalMaxSAT" - -echo "=================================================" -echo "OptiMin build script" -echo "=================================================" -echo - -echo "[*] Performing basic sanity checks..." - -PLT=`uname -s` - -if [ ! -f "../../config.h" ]; then - - echo "[-] Error: key files not found - wrong working directory?" - exit 1 - -fi - -LLVM_CONFIG="${LLVM_CONFIG:-llvm-config}" -CMAKECMD=cmake -MAKECMD=make -TARCMD=tar - -if [ "$PLT" = "Darwin" ]; then - CORES=`sysctl -n hw.ncpu` - TARCMD=tar -fi - -if [ "$PLT" = "FreeBSD" ]; then - MAKECMD=gmake - CORES=`sysctl -n hw.ncpu` - TARCMD=gtar -fi - -if [ "$PLT" = "NetBSD" ] || [ "$PLT" = "OpenBSD" ]; then - MAKECMD=gmake - CORES=`sysctl -n hw.ncpu` - TARCMD=gtar -fi - -PREREQ_NOTFOUND= -for i in git $CMAKECMD $MAKECMD $TARCMD; do - - T=`command -v "$i" 2>/dev/null` - - if [ "$T" = "" ]; then - - echo "[-] Error: '$i' not found. Run 'sudo apt-get install $i' or similar." - PREREQ_NOTFOUND=1 - - fi - -done - -if echo "$CC" | grep -qF /afl-; then - - echo "[-] Error: do not use afl-gcc or afl-clang to compile this tool." - PREREQ_NOTFOUND=1 - -fi - -if [ "$PREREQ_NOTFOUND" = "1" ]; then - exit 1 -fi - -echo "[+] All checks passed!" - -echo "[*] Making sure EvalMaxSAT is checked out" - -git status 1>/dev/null 2>/dev/null -if [ $? -eq 0 ]; then - echo "[*] initializing EvalMaxSAT submodule" - git submodule init || exit 1 - git submodule update ./EvalMaxSAT 2>/dev/null # ignore errors -else - echo "[*] cloning EvalMaxSAT" - test -d EvalMaxSAT || { - CNT=1 - while [ '!' -d EvalMaxSAT -a "$CNT" -lt 4 ]; do - echo "Trying to clone EvalMaxSAT (attempt $CNT/3)" - git clone "$EVALMAXSAT_REPO" - CNT=`expr "$CNT" + 1` - done - } -fi - -test -d EvalMaxSAT || { echo "[-] not checked out, please install git or check your internet connection." ; exit 1 ; } -echo "[+] Got EvalMaxSAT." - -cd "EvalMaxSAT" || exit 1 -echo "[*] Checking out $EVALMAXSAT_VERSION" -sh -c 'git stash && git stash drop' 1>/dev/null 2>/dev/null -git checkout "$EVALMAXSAT_VERSION" || exit 1 -cd .. - -echo -echo -echo "[+] EvalMaxSAT successfully prepared!" -echo "[+] Building OptiMin now." -mkdir -p build -cd build || exit 1 -cmake .. -DLLVM_DIR=`$LLVM_CONFIG --cmakedir` || exit 1 -make -j$CORES || exit 1 -cd .. -echo -cp -fv build/src/optimin . || exit 1 -echo "[+] OptiMin successfully built!" diff --git a/utils/optimin/src/CMakeLists.txt b/utils/optimin/src/CMakeLists.txt deleted file mode 100644 index 693f63f2..00000000 --- a/utils/optimin/src/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -add_executable(optimin OptiMin.cpp) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") - -foreach(LIB MaLib EvalMaxSAT glucose) - target_include_directories(optimin PRIVATE - "${CMAKE_SOURCE_DIR}/EvalMaxSAT/lib/${LIB}/src") - target_link_libraries(optimin ${LIB}) -endforeach(LIB) - -llvm_map_components_to_libnames(LLVM_LIBS support) -target_link_libraries(optimin ${LLVM_LIBS}) - -install(TARGETS optimin RUNTIME DESTINATION bin) diff --git a/utils/optimin/src/OptiMin.cpp b/utils/optimin/src/OptiMin.cpp deleted file mode 100644 index b0082d14..00000000 --- a/utils/optimin/src/OptiMin.cpp +++ /dev/null @@ -1,702 +0,0 @@ -/* - * OptiMin, an optimal fuzzing corpus minimizer. - * - * Author: Adrian Herrera - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "EvalMaxSAT.h" - -using namespace llvm; - -namespace { - -// -------------------------------------------------------------------------- // -// Classes -// -------------------------------------------------------------------------- // - -/// Ensure seed weights default to 1 -class Weight { - - public: - Weight() : Weight(1){}; - Weight(uint32_t V) : Value(V){}; - - operator unsigned() const { - - return Value; - - } - - private: - const unsigned Value; - -}; - -// -------------------------------------------------------------------------- // -// Typedefs -// -------------------------------------------------------------------------- // - -/// AFL tuple (edge) ID -using AFLTupleID = uint32_t; - -/// Pair of tuple ID and hit count -using AFLTuple = std::pair; - -/// Coverage for a given seed file -using AFLCoverageVector = std::vector; - -/// Map seed file paths to its coverage vector -using AFLCoverageMap = StringMap; - -/// Map seed file paths to a weight -using WeightsMap = StringMap; - -/// A seed identifier in the MaxSAT solver -using SeedID = int; - -/// Associates seed identifiers to seed files -using MaxSATSeeds = - SmallVector, 0>; - -/// Set of literal identifiers -using MaxSATSeedSet = DenseSet; - -/// Maps tuple IDs to the literal identifiers that "cover" that tuple -using MaxSATCoverageMap = DenseMap; - -// -------------------------------------------------------------------------- // -// Global variables -// -------------------------------------------------------------------------- // - -// This is based on the human class count in `count_class_human[256]` in -// `afl-showmap.c` -static constexpr uint32_t MAX_EDGE_FREQ = 8; - -// The maximum number of failures allowed when parsing a weights file -static constexpr unsigned MAX_WEIGHT_FAILURES = 5; - -static sys::TimePoint<> StartTime, EndTime; -static std::chrono::seconds Duration; - -static std::string ShowmapPath; -static bool TargetArgsHasAtAt = false; -static bool KeepTraces = false; -static bool SkipBinCheck = false; - -static const auto ErrMsg = [] { - - return WithColor(errs(), raw_ostream::RED, /*Bold=*/true) << "[-] "; - -}; - -static const auto WarnMsg = [] { - - return WithColor(errs(), raw_ostream::MAGENTA, /*Bold=*/true) << "[-] "; - -}; - -static const auto SuccMsg = [] { - - return WithColor(outs(), raw_ostream::GREEN, /*Bold=*/true) << "[+] "; - -}; - -static const auto StatMsg = [] { - - return WithColor(outs(), raw_ostream::BLUE, /*Bold=*/true) << "[*] "; - -}; - -static cl::opt InputDir("i", cl::desc("Input directory"), - cl::value_desc("dir"), cl::Required); -static cl::opt OutputDir("o", cl::desc("Output directory"), - cl::value_desc("dir"), cl::Required); - -static cl::opt EdgesOnly("f", cl::desc("Include edge hit counts"), - cl::init(true)); -static cl::opt WeightsFile("w", cl::desc("Weights file"), - cl::value_desc("csv")); - -static cl::opt TargetProg(cl::Positional, - cl::desc(""), - cl::Required); -static cl::list TargetArgs(cl::ConsumeAfter, - cl::desc("[target args...]")); - -static cl::opt MemLimit( - "m", cl::desc("Memory limit for child process (default=none)"), - cl::value_desc("megs"), cl::init("none")); -static cl::opt Timeout( - "t", cl::desc("Run time limit for child process (default=5000)"), - cl::value_desc("msec"), cl::init("5000")); - -static cl::opt CrashMode( - "C", cl::desc("Keep crashing inputs, reject everything else")); -static cl::opt FridaMode( - "O", cl::desc("Use binary-only instrumentation (FRIDA mode)")); -static cl::opt QemuMode( - "Q", cl::desc("Use binary-only instrumentation (QEMU mode)")); -static cl::opt UnicornMode( - "U", cl::desc("Use unicorn-based instrumentation (unicorn mode)")); - -} // anonymous namespace - -// -------------------------------------------------------------------------- // -// Helper functions -// -------------------------------------------------------------------------- // - -static void GetWeights(const MemoryBuffer &MB, WeightsMap &Weights) { - - SmallVector Lines; - MB.getBuffer().trim().split(Lines, '\n'); - - unsigned FailureCount = 0; - unsigned Weight = 0; - - for (const auto &Line : Lines) { - - const auto &[Seed, WeightStr] = Line.split(','); - - if (to_integer(WeightStr, Weight, 10)) { - - Weights.try_emplace(Seed, Weight); - - } else { - - if (FailureCount >= MAX_WEIGHT_FAILURES) { - ErrMsg() << "Too many failures. Aborting\n"; - std::exit(1); - } - - WarnMsg() << "Failed to read weight for '" << Seed << "'. Skipping...\n"; - FailureCount++; - - } - - } - -} - -static std::error_code readCov(const StringRef Trace, AFLCoverageVector &Cov) { - - const auto CovOrErr = MemoryBuffer::getFile(Trace); - if (const auto EC = CovOrErr.getError()) return EC; - - SmallVector Lines; - CovOrErr.get()->getBuffer().trim().split(Lines, '\n'); - - AFLTupleID Edge = 0; - unsigned Freq = 0; - - for (const auto &Line : Lines) { - - const auto &[EdgeStr, FreqStr] = Line.split(':'); - - to_integer(EdgeStr, Edge, 10); - to_integer(FreqStr, Freq, 10); - Cov.push_back({Edge, Freq}); - - } - - return std::error_code(); - -} - -static Error runShowmap(AFLCoverageMap &CovMap, const StringRef Input, - bool BinCheck = false) { - - const bool InputIsFile = !sys::fs::is_directory(Input); - Optional Redirects[] = {None, None, None}; - - SmallString<32> TraceDir{OutputDir}; - sys::path::append(TraceDir, ".traces"); - - SmallString<32> Output{TraceDir}; - SmallString<32> StdinFile{TraceDir}; - - // ------------------------------------------------------------------------ // - // Prepare afl-showmap arguments - // - // If the given input is a file, then feed this directly into stdin. - // Otherwise, if it is a directory, specify this on the afl-showmap command - // line. - // ------------------------------------------------------------------------ // - - SmallVector ShowmapArgs{ShowmapPath, "-q", - "-m", MemLimit, - "-t", Timeout}; - - if (InputIsFile) { - - StdinFile = Input; - sys::path::append(Output, - BinCheck ? ".run_test" : sys::path::filename(Input)); - - } else { - - sys::path::append(StdinFile, ".cur_input"); - ShowmapArgs.append({"-i", Input}); - - } - - - if (TargetArgsHasAtAt) { - - ShowmapArgs.append({"-H", StdinFile}); - Redirects[/* stdin */ 0] = "/dev/null"; - - } else if (InputIsFile) { - - Redirects[/* stdin */ 0] = Input; - - } - - if (FridaMode) ShowmapArgs.push_back("-O"); - if (QemuMode) ShowmapArgs.push_back("-Q"); - if (UnicornMode) ShowmapArgs.push_back("-U"); - - ShowmapArgs.append({"-o", Output, "--", TargetProg}); - ShowmapArgs.append(TargetArgs.begin(), TargetArgs.end()); - - // ------------------------------------------------------------------------ // - // Run afl-showmap - // ------------------------------------------------------------------------ // - - const int RC = sys::ExecuteAndWait(ShowmapPath, ShowmapArgs, - /*env=*/None, Redirects); - if (RC && !CrashMode) { - - ErrMsg() << "Exit code " << RC << " != 0 received from afl-showmap\n"; - return createStringError(inconvertibleErrorCode(), "afl-showmap failed"); - - } - - // ------------------------------------------------------------------------ // - // Parse afl-showmap output - // ------------------------------------------------------------------------ // - - AFLCoverageVector Cov; - std::error_code EC; - sys::fs::file_status Status; - - if (InputIsFile) { - - // Read a single output coverage file - if ((EC = readCov(Output, Cov))) { - - sys::fs::remove(Output); - return errorCodeToError(EC); - - } - - CovMap.try_emplace(sys::path::filename(Input), Cov); - if (!KeepTraces) sys::fs::remove(Output); - - } else { - - // Read a directory of output coverage files - for (sys::fs::recursive_directory_iterator Dir(TraceDir, EC), DirEnd; - Dir != DirEnd && !EC; Dir.increment(EC)) { - - if (EC) return errorCodeToError(EC); - - const auto &Path = Dir->path(); - if ((EC = sys::fs::status(Path, Status))) return errorCodeToError(EC); - - switch (Status.type()) { - - case sys::fs::file_type::regular_file: - case sys::fs::file_type::symlink_file: - case sys::fs::file_type::type_unknown: - Cov.clear(); - if ((EC = readCov(Path, Cov))) { - - sys::fs::remove(Path); - return errorCodeToError(EC); - - } - - CovMap.try_emplace(sys::path::filename(Path), Cov); - default: - // Ignore - break; - - } - - } - - if (!KeepTraces) sys::fs::remove_directories(TraceDir); - - } - - return Error::success(); - -} - -static inline void StartTimer() { - - StartTime = std::chrono::system_clock::now(); - -} - -static inline void EndTimer() { - - EndTime = std::chrono::system_clock::now(); - Duration = - std::chrono::duration_cast(EndTime - StartTime); - - SuccMsg() << " Completed in " << Duration.count() << " s\n"; - -} - -// -------------------------------------------------------------------------- // -// Main function -// -------------------------------------------------------------------------- // - -int main(int argc, char *argv[]) { - - WeightsMap Weights; - std::error_code EC; - - // ------------------------------------------------------------------------ // - // Parse command-line options and environment variables - // - // Also check the target arguments, as this determines how we run afl-showmap. - // ------------------------------------------------------------------------ // - - cl::ParseCommandLineOptions(argc, argv, "Optimal corpus minimizer"); - - KeepTraces = !!std::getenv("AFL_KEEP_TRACES"); - SkipBinCheck = !!std::getenv("AFL_SKIP_BIN_CHECK"); - const auto AFLPath = std::getenv("AFL_PATH"); - - if (CrashMode) ::setenv("AFL_CMIN_CRASHES_ONLY", "1", /*overwrite=*/true); - - for (const auto &Arg : TargetArgs) - if (Arg == "@@") TargetArgsHasAtAt = true; - - // ------------------------------------------------------------------------ // - // Find afl-showmap - // ------------------------------------------------------------------------ // - - SmallVector EnvPaths; - - if (const char *PathEnv = std::getenv("PATH")) - SplitString(PathEnv, EnvPaths, ":"); - if (AFLPath) EnvPaths.push_back(AFLPath); - - const auto ShowmapOrErr = sys::findProgramByName("afl-showmap", EnvPaths); - if (ShowmapOrErr.getError()) { - - ErrMsg() << "Failed to find afl-showmap. Check your PATH\n"; - return 1; - - } - - ShowmapPath = *ShowmapOrErr; - - // ------------------------------------------------------------------------ // - // Parse weights - // - // Weights are stored in CSV file mapping a seed file name to an integer - // greater than zero. - // ------------------------------------------------------------------------ // - - if (WeightsFile != "") { - - StatMsg() << "Reading weights from '" << WeightsFile << "'...\n"; - StartTimer(); - - const auto WeightsOrErr = MemoryBuffer::getFile(WeightsFile); - if ((EC = WeightsOrErr.getError())) { - - ErrMsg() << "Failed to read weights from '" << WeightsFile - << "': " << EC.message() << '\n'; - return 1; - - } - - GetWeights(*WeightsOrErr.get(), Weights); - - EndTimer(); - - } - - // ------------------------------------------------------------------------ // - // Traverse input directory - // - // Find the seed files inside this directory (and subdirectories). - // ------------------------------------------------------------------------ // - - StatMsg() << "Locating seeds in '" << InputDir << "'...\n"; - StartTimer(); - - bool IsDirResult; - if ((EC = sys::fs::is_directory(InputDir, IsDirResult))) { - - ErrMsg() << "Invalid input directory '" << InputDir << "': " << EC.message() - << '\n'; - return 1; - - } - - sys::fs::file_status Status; - StringMap SeedFiles; - - for (sys::fs::recursive_directory_iterator Dir(InputDir, EC), DirEnd; - Dir != DirEnd && !EC; Dir.increment(EC)) { - - if (EC) { - - ErrMsg() << "Failed to traverse input directory '" << InputDir - << "': " << EC.message() << '\n'; - return 1; - - } - - const auto &Path = Dir->path(); - if ((EC = sys::fs::status(Path, Status))) { - - ErrMsg() << "Failed to access '" << Path << "': " << EC.message() << '\n'; - return 1; - - } - - switch (Status.type()) { - - case sys::fs::file_type::regular_file: - case sys::fs::file_type::symlink_file: - case sys::fs::file_type::type_unknown: - SeedFiles.try_emplace(sys::path::filename(Path), - sys::path::parent_path(Path)); - default: - /* Ignore */ - break; - - } - - } - - EndTimer(); - - if (SeedFiles.empty()) { - - ErrMsg() << "Failed to find any seed files in '" << InputDir << "'\n"; - return 1; - - } - - // ------------------------------------------------------------------------ // - // Setup output directory - // ------------------------------------------------------------------------ // - - SmallString<32> TraceDir{OutputDir}; - sys::path::append(TraceDir, ".traces"); - - if ((EC = sys::fs::remove_directories(TraceDir))) { - - ErrMsg() << "Failed to remove existing trace directory in '" << OutputDir - << "': " << EC.message() << '\n'; - return 1; - - } - - if ((EC = sys::fs::create_directories(TraceDir))) { - - ErrMsg() << "Failed to create output directory '" << OutputDir - << "': " << EC.message() << '\n'; - return 1; - - } - - // ------------------------------------------------------------------------ // - // Test the target binary - // ------------------------------------------------------------------------ // - - AFLCoverageMap CovMap; - - if (!SkipBinCheck) { - - const auto It = SeedFiles.begin(); - SmallString<32> TestSeed{It->second}; - sys::path::append(TestSeed, It->first()); - - StatMsg() << "Testing the target binary with '" << TestSeed << "`...\n"; - StartTimer(); - - if (auto Err = runShowmap(CovMap, TestSeed, /*BinCheck=*/true)) { - - ErrMsg() << "No instrumentation output detected \n"; - return 1; - - } - - EndTimer(); - SuccMsg() << "OK, " << CovMap.begin()->second.size() - << " tuples recorded\n"; - - } - - // ------------------------------------------------------------------------ // - // Generate seed coverage - // - // Iterate over the corpus directory, which should contain seed files. Execute - // these seeds in the target program to generate coverage information, and - // then store this coverage information in the appropriate data structures. - // ------------------------------------------------------------------------ // - - StatMsg() << "Running afl-showmap on " << SeedFiles.size() << " seeds...\n"; - StartTimer(); - - MaxSATSeeds SeedVars; - MaxSATCoverageMap SeedCoverage; - EvalMaxSAT Solver(/*nbMinimizeThread=*/0); - - CovMap.clear(); - if (auto Err = runShowmap(CovMap, InputDir)) { - - ErrMsg() << "Failed to generate coverage: " << Err << '\n'; - return 1; - - } - - for (const auto &SeedCov : CovMap) { - - // Create a variable to represent the seed - const SeedID Var = Solver.newVar(); - SeedVars.emplace_back(Var, SeedCov.first()); - - // Record the set of seeds that cover a particular edge - for (auto &[Edge, Freq] : SeedCov.second) { - - if (EdgesOnly) { - - // Ignore edge frequency - SeedCoverage[Edge].insert(Var); - - } else { - - // Executing edge `E` `N` times means that it was executed `N - 1` times - for (unsigned I = 0; I < Freq; ++I) - SeedCoverage[MAX_EDGE_FREQ * Edge + I].insert(Var); - - } - - } - - } - - EndTimer(); - - // ------------------------------------------------------------------------ // - // Set the hard and soft constraints in the solver - // ------------------------------------------------------------------------ // - - StatMsg() << "Generating constraints...\n"; - StartTimer(); - - size_t SeedCount = 0; - - // Ensure that at least one seed is selected that covers a particular edge - // (hard constraint) - std::vector Clauses; - for (const auto &[_, Seeds] : SeedCoverage) { - - if (Seeds.empty()) continue; - - Clauses.clear(); - for (const auto &Seed : Seeds) - Clauses.push_back(Seed); - - Solver.addClause(Clauses); - - } - - // Select the minimum number of seeds that cover a particular set of edges - // (soft constraint) - for (const auto &[Var, Seed] : SeedVars) - Solver.addWeightedClause({-Var}, Weights[sys::path::filename(Seed)]); - - EndTimer(); - - // ------------------------------------------------------------------------ // - // Generate a solution - // ------------------------------------------------------------------------ // - - StatMsg() << "Solving...\n"; - StartTimer(); - - const bool Solved = Solver.solve(); - - EndTimer(); - - // ------------------------------------------------------------------------ // - // Save the solution - // - // This will copy the selected seeds to the given output directory. - // ------------------------------------------------------------------------ // - - SmallVector Solution; - SmallString<32> InputSeed, OutputSeed; - - if (Solved) { - - for (const auto &[Var, Seed] : SeedVars) - if (Solver.getValue(Var) > 0) Solution.push_back(Seed); - - } else { - - ErrMsg() << "Failed to find an optimal solution for '" << InputDir << "'\n"; - return 1; - - } - - StatMsg() << "Copying " << Solution.size() << " seeds to '" << OutputDir - << "'...\n"; - StartTimer(); - - SeedCount = 0; - - for (const auto &Seed : Solution) { - - InputSeed = SeedFiles[Seed]; - sys::path::append(InputSeed, Seed); - - OutputSeed = OutputDir; - sys::path::append(OutputSeed, Seed); - - if ((EC = sys::fs::copy_file(InputSeed, OutputSeed))) { - - ErrMsg() << "Failed to copy '" << Seed << "' to '" << OutputDir - << "': " << EC.message() << '\n'; - return 1; - - } - - } - - EndTimer(); - SuccMsg() << "Done!\n"; - - return 0; - -} - -- cgit 1.4.1 From 942b85bb77e25203c19a4a103e5d470c3a604b2f Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Tue, 31 May 2022 11:10:37 +0200 Subject: clarify gpl3 --- instrumentation/COPYING3 | 674 ----------------------------------- instrumentation/gcc_plugin.COPYING3 | 679 ++++++++++++++++++++++++++++++++++++ 2 files changed, 679 insertions(+), 674 deletions(-) delete mode 100644 instrumentation/COPYING3 create mode 100644 instrumentation/gcc_plugin.COPYING3 diff --git a/instrumentation/COPYING3 b/instrumentation/COPYING3 deleted file mode 100644 index 94a9ed02..00000000 --- a/instrumentation/COPYING3 +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/instrumentation/gcc_plugin.COPYING3 b/instrumentation/gcc_plugin.COPYING3 new file mode 100644 index 00000000..b0a36be4 --- /dev/null +++ b/instrumentation/gcc_plugin.COPYING3 @@ -0,0 +1,679 @@ +NOTE: +This license applies only to the gcc_plugin code "afl-gcc-pass.so.cc" as +gcc is GPL3 too. + + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. -- cgit 1.4.1 From ad2a1b05748c1ba72a36d0a569ec19b47d1a1236 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Tue, 31 May 2022 21:07:02 +0100 Subject: libdislocator on macOS to get memory block size is malloc_size is instead. --- utils/libdislocator/libdislocator.so.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/libdislocator/libdislocator.so.c b/utils/libdislocator/libdislocator.so.c index bd08a678..1b4a7316 100644 --- a/utils/libdislocator/libdislocator.so.c +++ b/utils/libdislocator/libdislocator.so.c @@ -505,7 +505,10 @@ void *reallocarray(void *ptr, size_t elem_len, size_t elem_cnt) { } -#if !defined(__ANDROID__) +#if defined(__APPLE__) +size_t malloc_size(const void *ptr) { + +#elif !defined(__ANDROID__) size_t malloc_usable_size(void *ptr) { #else -- cgit 1.4.1 From 6afccdebcd8b771c1b8eed2bd71d7b81985a9c83 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 2 Jun 2022 21:48:15 +0100 Subject: libdislocator, introduces malloc_good_size for Darwin. --- utils/libdislocator/libdislocator.so.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils/libdislocator/libdislocator.so.c b/utils/libdislocator/libdislocator.so.c index 1b4a7316..fecf3bc6 100644 --- a/utils/libdislocator/libdislocator.so.c +++ b/utils/libdislocator/libdislocator.so.c @@ -520,6 +520,14 @@ size_t malloc_usable_size(const void *ptr) { } +#if defined(__APPLE__) +size_t malloc_good_size(size_t len) { + + return (len & ~(ALLOC_ALIGN_SIZE - 1)) + ALLOC_ALIGN_SIZE; + +} +#endif + __attribute__((constructor)) void __dislocator_init(void) { char *tmp = getenv("AFL_LD_LIMIT_MB"); -- cgit 1.4.1 From 683dcc471083540da20468a4ba505bc4f3d7bbf4 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Mon, 6 Jun 2022 19:26:18 +0200 Subject: remove existing shared modules when installing --- GNUmakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/GNUmakefile b/GNUmakefile index 072bd09d..42d48b68 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -696,6 +696,7 @@ install: all $(MANPAGES) @rm -f $${DESTDIR}$(BIN_PATH)/afl-plot.sh @rm -f $${DESTDIR}$(BIN_PATH)/afl-as @rm -f $${DESTDIR}$(HELPER_PATH)/afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH)/afl-llvm-rt-32.o $${DESTDIR}$(HELPER_PATH)/afl-llvm-rt-64.o $${DESTDIR}$(HELPER_PATH)/afl-gcc-rt.o + @for i in afl-llvm-dict2file.so afl-llvm-lto-instrumentlist.so afl-llvm-pass.so cmplog-instructions-pass.so cmplog-routines-pass.so cmplog-switches-pass.so compare-transform-pass.so libcompcov.so libdislocator.so libnyx.so libqasan.so libtokencap.so SanitizerCoverageLTO.so SanitizerCoveragePCGUARD.so split-compares-pass.so split-switches-pass.so; do echo rm -fv $${DESTDIR}$(HELPER_PATH)/$${i}; done install -m 755 $(PROGS) $(SH_PROGS) $${DESTDIR}$(BIN_PATH) @if [ -f afl-qemu-trace ]; then install -m 755 afl-qemu-trace $${DESTDIR}$(BIN_PATH); fi @if [ -f utils/plot_ui/afl-plot-ui ]; then install -m 755 utils/plot_ui/afl-plot-ui $${DESTDIR}$(BIN_PATH); fi -- cgit 1.4.1 From 83f32c5248c8a8a1e69ca2f6f392c27c1736eef1 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Wed, 8 Jun 2022 10:56:11 +0200 Subject: honor AFL_MAP_SIZE well outside of afl++ --- instrumentation/afl-compiler-rt.o.c | 31 +++++++++++++++++++++++++++++-- src/afl-fuzz-run.c | 6 +----- src/afl-fuzz-state.c | 13 ++++++++++--- utils/libdislocator/libdislocator.so.c | 1 + 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c index db7ac7b0..b94e3dc9 100644 --- a/instrumentation/afl-compiler-rt.o.c +++ b/instrumentation/afl-compiler-rt.o.c @@ -327,6 +327,31 @@ static void __afl_map_shm(void) { } + if (!id_str) { + + u32 val = 0; + u8 *ptr; + + if ((ptr = getenv("AFL_MAP_SIZE")) != NULL) val = atoi(ptr); + + if (val > MAP_INITIAL_SIZE) { + + __afl_map_size = val; + __afl_final_loc = val; + __afl_area_ptr_dummy = malloc(__afl_map_size); + if (!__afl_area_ptr_dummy) { + + fprintf(stderr, + "Error: AFL++ could not aquire %u bytes of memory, exiting!\n", + __afl_map_size); + exit(-1); + + } + + } + + } + /* If we're running under AFL, attach to the appropriate region, replacing the early-stage __afl_area_initial region that is needed to allow some really hacky .init code to work correctly in projects such as OpenSSL. */ @@ -465,7 +490,9 @@ static void __afl_map_shm(void) { } - } else if (_is_sancov && __afl_area_ptr != __afl_area_initial) { + } else if (_is_sancov && __afl_area_ptr != __afl_area_initial && + + __afl_area_ptr != __afl_area_ptr_dummy) { free(__afl_area_ptr); __afl_area_ptr = NULL; @@ -487,7 +514,7 @@ static void __afl_map_shm(void) { fprintf(stderr, "DEBUG: (2) id_str %s, __afl_area_ptr %p, __afl_area_initial %p, " "__afl_area_ptr_dummy %p, __afl_map_addr 0x%llx, MAP_SIZE " - "%u, __afl_final_loc %u, __afl_map_size %u," + "%u, __afl_final_loc %u, __afl_map_size %u, " "max_size_forkserver %u/0x%x\n", id_str == NULL ? "" : id_str, __afl_area_ptr, __afl_area_initial, __afl_area_ptr_dummy, __afl_map_addr, MAP_SIZE, diff --git a/src/afl-fuzz-run.c b/src/afl-fuzz-run.c index 09e773f0..5703a66a 100644 --- a/src/afl-fuzz-run.c +++ b/src/afl-fuzz-run.c @@ -130,11 +130,7 @@ write_to_testcase(afl_state_t *afl, void **mem, u32 len, u32 fix) { } - if (new_mem != *mem) { - - *mem = new_mem; - - } + if (new_mem != *mem) { *mem = new_mem; } /* everything as planned. use the potentially new data. */ afl_fsrv_write_to_testcase(&afl->fsrv, *mem, new_size); diff --git a/src/afl-fuzz-state.c b/src/afl-fuzz-state.c index cbe32c75..8334af75 100644 --- a/src/afl-fuzz-state.c +++ b/src/afl-fuzz-state.c @@ -526,11 +526,18 @@ void read_afl_environment(afl_state_t *afl, char **envp) { int time = atoi((u8 *)get_afl_env(afl_environment_variables[i])); if (time > 0) { - afl->sync_time = time * (60 * 1000LL); + + afl->sync_time = time * (60 * 1000LL); + } else { - WARNF("incorrect value for AFL_SYNC_TIME environment variable, " - "used default value %lld instead.", afl->sync_time / 60 / 1000); + + WARNF( + "incorrect value for AFL_SYNC_TIME environment variable, " + "used default value %lld instead.", + afl->sync_time / 60 / 1000); + } + } } else { diff --git a/utils/libdislocator/libdislocator.so.c b/utils/libdislocator/libdislocator.so.c index fecf3bc6..c821a8f7 100644 --- a/utils/libdislocator/libdislocator.so.c +++ b/utils/libdislocator/libdislocator.so.c @@ -526,6 +526,7 @@ size_t malloc_good_size(size_t len) { return (len & ~(ALLOC_ALIGN_SIZE - 1)) + ALLOC_ALIGN_SIZE; } + #endif __attribute__((constructor)) void __dislocator_init(void) { -- cgit 1.4.1 From 35d49c7c5c398c6de5d3091fdda298e45726ae1b Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Wed, 8 Jun 2022 12:46:08 +0200 Subject: fix --- instrumentation/afl-compiler-rt.o.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c index b94e3dc9..f3a16e95 100644 --- a/instrumentation/afl-compiler-rt.o.c +++ b/instrumentation/afl-compiler-rt.o.c @@ -327,7 +327,7 @@ static void __afl_map_shm(void) { } - if (!id_str) { + if (!id_str && __afl_area_ptr_dummy == __afl_area_initial) { u32 val = 0; u8 *ptr; @@ -337,7 +337,6 @@ static void __afl_map_shm(void) { if (val > MAP_INITIAL_SIZE) { __afl_map_size = val; - __afl_final_loc = val; __afl_area_ptr_dummy = malloc(__afl_map_size); if (!__afl_area_ptr_dummy) { @@ -348,6 +347,17 @@ static void __afl_map_shm(void) { } + } else { + + __afl_map_size = MAP_INITIAL_SIZE; + + } + + if (__afl_debug) { + + fprintf(stderr, "DEBUG: (0) init map size is %u to %p\n", __afl_map_size, + __afl_area_ptr_dummy); + } } @@ -490,20 +500,26 @@ static void __afl_map_shm(void) { } - } else if (_is_sancov && __afl_area_ptr != __afl_area_initial && + } else if (__afl_final_loc > __afl_map_size) { - __afl_area_ptr != __afl_area_ptr_dummy) { + if (__afl_area_initial != __afl_area_ptr_dummy) { - free(__afl_area_ptr); - __afl_area_ptr = NULL; + free(__afl_area_ptr_dummy); - if (__afl_final_loc > MAP_INITIAL_SIZE) { + } - __afl_area_ptr = (u8 *)malloc(__afl_final_loc); + __afl_area_ptr_dummy = (u8 *)malloc(__afl_final_loc); + __afl_area_ptr = __afl_area_ptr_dummy; + __afl_map_size = __afl_final_loc; - } + if (!__afl_area_ptr_dummy) { - if (!__afl_area_ptr) { __afl_area_ptr = __afl_area_ptr_dummy; } + fprintf(stderr, + "Error: AFL++ could not aquire %u bytes of memory, exiting!\n", + __afl_final_loc); + exit(-1); + + } } -- cgit 1.4.1 From d798a90f042e4fcaa181523ec8409a6d17bca66c Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Thu, 9 Jun 2022 10:11:41 +0200 Subject: uc update --- coresight_mode/patchelf | 2 +- custom_mutators/gramatron/json-c | 2 +- unicorn_mode/UNICORNAFL_VERSION | 2 +- unicorn_mode/unicornafl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/coresight_mode/patchelf b/coresight_mode/patchelf index 7ec8edbe..be0cc30a 160000 --- a/coresight_mode/patchelf +++ b/coresight_mode/patchelf @@ -1 +1 @@ -Subproject commit 7ec8edbe094ee13c91dadca191f92b9dfac8c0f9 +Subproject commit be0cc30a59b2755844bcd48823f6fbc8d97b93a7 diff --git a/custom_mutators/gramatron/json-c b/custom_mutators/gramatron/json-c index af8dd4a3..11546bfd 160000 --- a/custom_mutators/gramatron/json-c +++ b/custom_mutators/gramatron/json-c @@ -1 +1 @@ -Subproject commit af8dd4a307e7b837f9fa2959549548ace4afe08b +Subproject commit 11546bfd07a575c47416924cb98de3d33a4e6424 diff --git a/unicorn_mode/UNICORNAFL_VERSION b/unicorn_mode/UNICORNAFL_VERSION index 77fc69b5..5e7234c6 100644 --- a/unicorn_mode/UNICORNAFL_VERSION +++ b/unicorn_mode/UNICORNAFL_VERSION @@ -1 +1 @@ -c3e15a7d +06796154996fef2d92ccd172181ee0cdf3631959 diff --git a/unicorn_mode/unicornafl b/unicorn_mode/unicornafl index c3e15a7d..06796154 160000 --- a/unicorn_mode/unicornafl +++ b/unicorn_mode/unicornafl @@ -1 +1 @@ -Subproject commit c3e15a7d44101ff288abe114b7954ce6cfa070b1 +Subproject commit 06796154996fef2d92ccd172181ee0cdf3631959 -- cgit 1.4.1 From b595727f2fe42dcd2e85a733fd2f2c321920b0d2 Mon Sep 17 00:00:00 2001 From: Tobias Scharnowski Date: Fri, 10 Jun 2022 18:38:37 +0200 Subject: Fix Byte Decrement Havoc Mutation While looking at the source code of the havoc mutations I realized that there seems to be a typo / copy+paste error with the SUBBYTE_ mutation. It is currently incrementing, instead of decrementing the value. Alternative Fix: Change the documentation to "/* Decrease byte by minus 1. */" to make it work as documented :-P --- src/afl-fuzz-one.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/afl-fuzz-one.c b/src/afl-fuzz-one.c index 19f41ebe..ef80524f 100644 --- a/src/afl-fuzz-one.c +++ b/src/afl-fuzz-one.c @@ -2585,7 +2585,7 @@ havoc_stage: snprintf(afl->m_tmp, sizeof(afl->m_tmp), " SUBBYTE_"); strcat(afl->mutation, afl->m_tmp); #endif - out_buf[rand_below(afl, temp_len)]++; + out_buf[rand_below(afl, temp_len)]--; break; } -- cgit 1.4.1 From da1b0410984c244881d818239372ba7ac07e36c3 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Sun, 12 Jun 2022 08:24:32 +0200 Subject: update changelog --- docs/Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/Changelog.md b/docs/Changelog.md index 6269e3b1..4091c5f9 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -28,6 +28,7 @@ sending a mail to . kept), unless AFL_KEEP_TIMEOUTS are set - AFL never implemented auto token inserts (but user token inserts, user token overwrite and auto token overwrite), added now! + - fixed for a mutation type in havoc mode - Mopt fix to always select the correct algorithm - fix effector map calculation (deterministic mode) - fix custom mutator post_process functionality -- cgit 1.4.1 From 5b471986b834a1aa0c58701f4acf4d58d3951605 Mon Sep 17 00:00:00 2001 From: hexcoder Date: Tue, 14 Jun 2022 14:52:48 +0200 Subject: add line feed at end --- custom_mutators/gramatron/testMakefile.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_mutators/gramatron/testMakefile.mk b/custom_mutators/gramatron/testMakefile.mk index 0b2c6236..ff19826b 100644 --- a/custom_mutators/gramatron/testMakefile.mk +++ b/custom_mutators/gramatron/testMakefile.mk @@ -1,2 +1,3 @@ test: test.c - gcc -g -fPIC -Wno-unused-result -Wl,--allow-multiple-definition -I../../include -o test -I. -I/prg/dev/include test.c gramfuzz-helpers.c gramfuzz-mutators.c gramfuzz-util.c hashmap.c ../../src/afl-performance.o json-c/.libs/libjson-c.a \ No newline at end of file + gcc -g -fPIC -Wno-unused-result -Wl,--allow-multiple-definition -I../../include -o test -I. -I/prg/dev/include test.c gramfuzz-helpers.c gramfuzz-mutators.c gramfuzz-util.c hashmap.c ../../src/afl-performance.o json-c/.libs/libjson-c.a + -- cgit 1.4.1 From ba21e20695313d538535788cdc55f4b26304e56a Mon Sep 17 00:00:00 2001 From: hexcoder Date: Tue, 14 Jun 2022 14:56:10 +0200 Subject: typo --- docs/env_variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/env_variables.md b/docs/env_variables.md index 3c69c0b6..a63aad10 100644 --- a/docs/env_variables.md +++ b/docs/env_variables.md @@ -519,7 +519,7 @@ checks or alter some of the more exotic semantics of the tool: - `AFL_SYNC_TIME` allows you to specify a different minimal time (in minutes) between fuzzing instances synchronization. Default sync time is 30 minutes, - note that time is halfed for -M main nodes. + note that time is halved for -M main nodes. - Setting `AFL_TARGET_ENV` causes AFL++ to set extra environment variables for the target binary. Example: `AFL_TARGET_ENV="VAR1=1 VAR2='a b c'" afl-fuzz -- cgit 1.4.1 From 80892b8fc597fcfa73bd9f105d3f0f4171a92c57 Mon Sep 17 00:00:00 2001 From: hexcoder Date: Tue, 14 Jun 2022 14:57:31 +0200 Subject: typos --- docs/Changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 4091c5f9..44939b16 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -28,7 +28,7 @@ sending a mail to . kept), unless AFL_KEEP_TIMEOUTS are set - AFL never implemented auto token inserts (but user token inserts, user token overwrite and auto token overwrite), added now! - - fixed for a mutation type in havoc mode + - fixed a mutation type in havoc mode - Mopt fix to always select the correct algorithm - fix effector map calculation (deterministic mode) - fix custom mutator post_process functionality @@ -43,7 +43,7 @@ sending a mail to . - unicorn_mode: - update unicorn engine, fix C example - utils: - - removed optimin because it looses coverage due a bug and is + - removed optimin because it looses coverage due to a bug and is unmaintained :-( -- cgit 1.4.1 From 47d894747169692362eb0266017753e0838ecc2c Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Fri, 17 Jun 2022 12:10:11 -0400 Subject: require value in env --- src/afl-fuzz-init.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c index 6a653a00..aedbd996 100644 --- a/src/afl-fuzz-init.c +++ b/src/afl-fuzz-init.c @@ -113,7 +113,7 @@ void bind_to_free_cpu(afl_state_t *afl) { u8 lockfile[PATH_MAX] = ""; s32 i; - if (afl->afl_env.afl_no_affinity && !afl->afl_env.afl_try_affinity) { + if (afl->afl_env.afl_no_affinity = 1 && afl->afl_env.afl_try_affinity != 1) { if (afl->cpu_to_bind != -1) { @@ -130,7 +130,7 @@ void bind_to_free_cpu(afl_state_t *afl) { if (!bind_cpu(afl, afl->cpu_to_bind)) { - if (afl->afl_env.afl_try_affinity) { + if (afl->afl_env.afl_try_affinity = 1) { WARNF( "Could not bind to requested CPU %d! Make sure you passed a valid " @@ -2957,4 +2957,3 @@ void save_cmdline(afl_state_t *afl, u32 argc, char **argv) { *buf = 0; } - -- cgit 1.4.1 From 3d1a57deed63bdff6c817e1b1a8098df94ea5eac Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Fri, 17 Jun 2022 21:03:46 +0200 Subject: feat: allow to skip readme creation on crash --- docs/env_variables.md | 4 ++++ include/afl-fuzz.h | 3 +-- include/envs.h | 2 +- src/afl-fuzz-bitmap.c | 3 +-- src/afl-fuzz-state.c | 9 ++++++++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/env_variables.md b/docs/env_variables.md index a63aad10..0598a809 100644 --- a/docs/env_variables.md +++ b/docs/env_variables.md @@ -619,6 +619,10 @@ The QEMU wrapper used to instrument binary-only code supports several settings: emulation" variables (e.g., `QEMU_STACK_SIZE`), but there should be no reason to touch them. + - Normally a `README.txt` is written to the `crashes/` directory when a first + crash is found. Setting `AFL_NO_CRASH_README` will prevent this. Useful when + counting crashes based on a file count in that directory. + ## 7) Settings for afl-frida-trace The FRIDA wrapper used to instrument binary-only code supports many of the same diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h index 24af426f..b78d0b98 100644 --- a/include/afl-fuzz.h +++ b/include/afl-fuzz.h @@ -386,7 +386,7 @@ typedef struct afl_env_vars { afl_bench_until_crash, afl_debug_child, afl_autoresume, afl_cal_fast, afl_cycle_schedules, afl_expand_havoc, afl_statsd, afl_cmplog_only_new, afl_exit_on_seed_issues, afl_try_affinity, afl_ignore_problems, - afl_keep_timeouts, afl_pizza_mode; + afl_keep_timeouts, afl_pizza_mode, afl_no_crash_readme; u8 *afl_tmpdir, *afl_custom_mutator_library, *afl_python_module, *afl_path, *afl_hang_tmout, *afl_forksrv_init_tmout, *afl_preload, @@ -1267,4 +1267,3 @@ void queue_testcase_store_mem(afl_state_t *afl, struct queue_entry *q, u8 *mem); #endif #endif - diff --git a/include/envs.h b/include/envs.h index f4cccc96..4105ac6d 100644 --- a/include/envs.h +++ b/include/envs.h @@ -159,6 +159,7 @@ static char *afl_environment_variables[] = { "AFL_NO_COLOUR", #endif "AFL_NO_CPU_RED", + "AFL_NO_CRASH_README", "AFL_NO_FORKSRV", "AFL_NO_UI", "AFL_NO_PYTHON", @@ -234,4 +235,3 @@ static char *afl_environment_variables[] = { extern char *afl_environment_variables[]; #endif - diff --git a/src/afl-fuzz-bitmap.c b/src/afl-fuzz-bitmap.c index 26e70d81..fffcef89 100644 --- a/src/afl-fuzz-bitmap.c +++ b/src/afl-fuzz-bitmap.c @@ -720,7 +720,7 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) { } - if (unlikely(!afl->saved_crashes)) { write_crash_readme(afl); } + if (unlikely(!afl->saved_crashes) && (afl->afl_env.afl_no_crash_readme != 1)) { write_crash_readme(afl); } #ifndef SIMPLE_FILES @@ -821,4 +821,3 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) { return keeping; } - diff --git a/src/afl-fuzz-state.c b/src/afl-fuzz-state.c index 8334af75..4d16811f 100644 --- a/src/afl-fuzz-state.c +++ b/src/afl-fuzz-state.c @@ -510,6 +510,14 @@ void read_afl_environment(afl_state_t *afl, char **envp) { afl->afl_env.afl_pizza_mode = atoi((u8 *)get_afl_env(afl_environment_variables[i])); + + } else if (!strncmp(env, "AFL_NO_CRASH_README", + + afl_environment_variable_len)) { + + afl->afl_env.afl_no_crash_readme = + atoi((u8 *)get_afl_env(afl_environment_variables[i])); + if (afl->afl_env.afl_pizza_mode == 0) { afl->afl_env.afl_pizza_mode = 1; @@ -665,4 +673,3 @@ void afl_states_request_skip(void) { LIST_FOREACH(&afl_states, afl_state_t, { el->skip_requested = 1; }); } - -- cgit 1.4.1 From 499082384094e9cb3ff4fe18ee068e302e550aa3 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Fri, 17 Jun 2022 21:08:37 +0200 Subject: formatting --- include/afl-fuzz.h | 1 + include/envs.h | 1 + src/afl-fuzz-bitmap.c | 8 +++++++- src/afl-fuzz-state.c | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h index b78d0b98..ce42a107 100644 --- a/include/afl-fuzz.h +++ b/include/afl-fuzz.h @@ -1267,3 +1267,4 @@ void queue_testcase_store_mem(afl_state_t *afl, struct queue_entry *q, u8 *mem); #endif #endif + diff --git a/include/envs.h b/include/envs.h index 4105ac6d..9b8917f9 100644 --- a/include/envs.h +++ b/include/envs.h @@ -235,3 +235,4 @@ static char *afl_environment_variables[] = { extern char *afl_environment_variables[]; #endif + diff --git a/src/afl-fuzz-bitmap.c b/src/afl-fuzz-bitmap.c index fffcef89..089f7bb5 100644 --- a/src/afl-fuzz-bitmap.c +++ b/src/afl-fuzz-bitmap.c @@ -720,7 +720,12 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) { } - if (unlikely(!afl->saved_crashes) && (afl->afl_env.afl_no_crash_readme != 1)) { write_crash_readme(afl); } + if (unlikely(!afl->saved_crashes) && + (afl->afl_env.afl_no_crash_readme != 1)) { + + write_crash_readme(afl); + + } #ifndef SIMPLE_FILES @@ -821,3 +826,4 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) { return keeping; } + diff --git a/src/afl-fuzz-state.c b/src/afl-fuzz-state.c index 4d16811f..cc4138ae 100644 --- a/src/afl-fuzz-state.c +++ b/src/afl-fuzz-state.c @@ -673,3 +673,4 @@ void afl_states_request_skip(void) { LIST_FOREACH(&afl_states, afl_state_t, { el->skip_requested = 1; }); } + -- cgit 1.4.1 From 4fdd1129f01cc6936f0f79668cdd52e77650718a Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Fri, 17 Jun 2022 21:21:34 +0200 Subject: feat: push both dev and stable --- .github/workflows/build_aflplusplus_docker.yaml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_aflplusplus_docker.yaml b/.github/workflows/build_aflplusplus_docker.yaml index fa96da8e..b3f82453 100644 --- a/.github/workflows/build_aflplusplus_docker.yaml +++ b/.github/workflows/build_aflplusplus_docker.yaml @@ -2,7 +2,9 @@ name: Publish Docker Images on: push: - branches: [ stable ] + branches: + - stable + - dev # paths: # - Dockerfile @@ -21,10 +23,18 @@ jobs: with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} - - name: Publish aflpp to Registry + - name: Publish aflpp ${{ github.ref }} to Registry + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: aflplusplus/aflplusplus:${{ github.ref }} + - name: Publish aflpp dev as latest to Registry uses: docker/build-push-action@v2 with: context: . platforms: linux/amd64,linux/arm64 push: true tags: aflplusplus/aflplusplus:latest + if: "${{ github.ref }}" == "dev" -- cgit 1.4.1 From 0dd1c39b5a011c34c02c4c2ae3a975ffaa01ca75 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 02:35:31 +0200 Subject: check for empty env var as well --- src/afl-common.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/afl-common.c b/src/afl-common.c index eca7d272..abf7e70a 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -715,17 +715,23 @@ char *get_afl_env(char *env) { char *val; - if ((val = getenv(env)) != NULL) { + if ((val = getenv(env))) { - if (!be_quiet) { + if (*val) { + + if (!be_quiet) { + + OKF("Loaded environment variable %s with value %s", env, val); - OKF("Loaded environment variable %s with value %s", env, val); + } + + return val; } } - return val; + return NULL; } @@ -1243,4 +1249,3 @@ s32 create_file(u8 *fn) { return fd; } - -- cgit 1.4.1 From fc3b483450280f01c214853db5c4d30aa1eff1c1 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 02:35:40 +0200 Subject: revert previous changes --- src/afl-fuzz-init.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c index aedbd996..6a653a00 100644 --- a/src/afl-fuzz-init.c +++ b/src/afl-fuzz-init.c @@ -113,7 +113,7 @@ void bind_to_free_cpu(afl_state_t *afl) { u8 lockfile[PATH_MAX] = ""; s32 i; - if (afl->afl_env.afl_no_affinity = 1 && afl->afl_env.afl_try_affinity != 1) { + if (afl->afl_env.afl_no_affinity && !afl->afl_env.afl_try_affinity) { if (afl->cpu_to_bind != -1) { @@ -130,7 +130,7 @@ void bind_to_free_cpu(afl_state_t *afl) { if (!bind_cpu(afl, afl->cpu_to_bind)) { - if (afl->afl_env.afl_try_affinity = 1) { + if (afl->afl_env.afl_try_affinity) { WARNF( "Could not bind to requested CPU %d! Make sure you passed a valid " @@ -2957,3 +2957,4 @@ void save_cmdline(afl_state_t *afl, u32 argc, char **argv) { *buf = 0; } + -- cgit 1.4.1 From bf6a0159a934b750d22cc34210544fdb3418df7f Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 02:37:11 +0200 Subject: formatting --- src/afl-common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/afl-common.c b/src/afl-common.c index abf7e70a..cbf20fba 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -1249,3 +1249,4 @@ s32 create_file(u8 *fn) { return fd; } + -- cgit 1.4.1 From be79ee70722fc185e6ce651c2071c72016c15792 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 02:52:57 +0200 Subject: stable==latest --- .github/workflows/build_aflplusplus_docker.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_aflplusplus_docker.yaml b/.github/workflows/build_aflplusplus_docker.yaml index b3f82453..ff7bc4da 100644 --- a/.github/workflows/build_aflplusplus_docker.yaml +++ b/.github/workflows/build_aflplusplus_docker.yaml @@ -5,8 +5,6 @@ on: branches: - stable - dev -# paths: -# - Dockerfile jobs: push_to_registry: @@ -30,11 +28,12 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: aflplusplus/aflplusplus:${{ github.ref }} + if: "${{ github.ref }}" == "dev" - name: Publish aflpp dev as latest to Registry uses: docker/build-push-action@v2 with: context: . platforms: linux/amd64,linux/arm64 push: true - tags: aflplusplus/aflplusplus:latest - if: "${{ github.ref }}" == "dev" + tags: aflplusplus/aflplusplus:${{ github.ref }},aflplusplus/aflplusplus:latest + if: "${{ github.ref }}" == "stable" -- cgit 1.4.1 From 74f70d0c74b0ddd631ede19069106cd29f0c4aad Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 02:55:27 +0200 Subject: update name --- .github/workflows/build_aflplusplus_docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_aflplusplus_docker.yaml b/.github/workflows/build_aflplusplus_docker.yaml index ff7bc4da..a26f31d2 100644 --- a/.github/workflows/build_aflplusplus_docker.yaml +++ b/.github/workflows/build_aflplusplus_docker.yaml @@ -29,7 +29,7 @@ jobs: push: true tags: aflplusplus/aflplusplus:${{ github.ref }} if: "${{ github.ref }}" == "dev" - - name: Publish aflpp dev as latest to Registry + - name: Publish aflpp ${{ github.ref }} and latest to Registry uses: docker/build-push-action@v2 with: context: . -- cgit 1.4.1 From dc3e2e8200037b4f7d14a15459ed7fa6fa3260a2 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Sat, 18 Jun 2022 09:06:27 +0200 Subject: update docs --- README.md | 3 +++ docs/INSTALL.md | 3 +++ docs/tutorials.md | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a29ce792..c3a627ec 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,9 @@ This image is automatically generated when a push to the stable repo happens (see [branches](#branches)). If you use the command above, you will find your target source code in `/src` in the container. +Note: you can also pull `aflplusplus/aflplusplus:dev` which is the most current +development state of AFL++. + To build AFL++ yourself - *which we recommend* - continue at [docs/INSTALL.md](docs/INSTALL.md). diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 01343b7f..754621b5 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -15,6 +15,9 @@ docker run -ti -v /location/of/your/target:/src aflplusplus/aflplusplus This image is automatically generated when a push to the stable repo happens. You will find your target source code in `/src` in the container. +Note: you can also pull `aflplusplus/aflplusplus:dev` which is the most current +development state of AFL++. + If you want to build AFL++ yourself, you have many options. The easiest choice is to build and install everything: diff --git a/docs/tutorials.md b/docs/tutorials.md index 64d2b376..477ff98b 100644 --- a/docs/tutorials.md +++ b/docs/tutorials.md @@ -1,5 +1,9 @@ # Tutorials +If you are a total newbie, try this guide: + +* [https://github.com/alex-maleno/Fuzzing-Module](https://github.com/alex-maleno/Fuzzing-Module) + Here are some good write-ups to show how to effectively use AFL++: * [https://aflplus.plus/docs/tutorials/libxml2_tutorial/](https://aflplus.plus/docs/tutorials/libxml2_tutorial/) @@ -17,7 +21,7 @@ training, then we can highly recommend the following: * [https://github.com/antonio-morales/Fuzzing101](https://github.com/antonio-morales/Fuzzing101) If you are interested in fuzzing structured data (where you define what the -structure is), these links have you covered: +structure is), these links have you covered (some are outdated though): * libprotobuf for AFL++: [https://github.com/P1umer/AFLplusplus-protobuf-mutator](https://github.com/P1umer/AFLplusplus-protobuf-mutator) -- cgit 1.4.1 From 605f2bf96936efd6c5193d106a32fcf893c26b56 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Sat, 18 Jun 2022 09:14:44 +0200 Subject: code format --- custom_mutators/gramatron/automaton-parser.c | 476 +++++++++++++++++--------- custom_mutators/gramatron/automaton-parser.h | 47 +-- custom_mutators/gramatron/gramfuzz-mutators.c | 3 +- custom_mutators/gramatron/gramfuzz.c | 37 +- custom_mutators/gramatron/hashmap.c | 1 + custom_mutators/gramatron/uthash.h | 41 +-- 6 files changed, 385 insertions(+), 220 deletions(-) diff --git a/custom_mutators/gramatron/automaton-parser.c b/custom_mutators/gramatron/automaton-parser.c index 3265e0cf..266f5a07 100644 --- a/custom_mutators/gramatron/automaton-parser.c +++ b/custom_mutators/gramatron/automaton-parser.c @@ -2,287 +2,409 @@ #include "automaton-parser.h" int free_terminal_arr(any_t placeholder, any_t item) { - struct terminal_arr* tmp = item; + + struct terminal_arr *tmp = item; free(tmp->start); free(tmp); return MAP_OK; + } -int compare_two_symbols(const void * a, const void * b) { - char* a_char = *(char **)a; - char* b_char = *(char **)b; - size_t fa = strlen(a_char); - size_t fb = strlen(b_char); - if (fa > fb) return -1; - else if (fa == fb) return 0; - else return 1; +int compare_two_symbols(const void *a, const void *b) { + + char * a_char = *(char **)a; + char * b_char = *(char **)b; + size_t fa = strlen(a_char); + size_t fb = strlen(b_char); + if (fa > fb) + return -1; + else if (fa == fb) + return 0; + else + return 1; } // TODO: create a map -// key: first character of a symbol, value: a list of symbols that starts with key, the list is sorted in descending order of the symbol lengths -map_t create_first_char_to_symbols_hashmap(struct symbols_arr *symbols, struct symbols_arr *first_chars) { +// key: first character of a symbol, value: a list of symbols that starts with +// key, the list is sorted in descending order of the symbol lengths +map_t create_first_char_to_symbols_hashmap(struct symbols_arr *symbols, + struct symbols_arr *first_chars) { + map_t char_to_symbols = hashmap_new(); // TODO: free the allocated map // sort the symbol_dict in descending order of the symbol lengths - qsort(symbols->symbols_arr, symbols->len, sizeof(char*), compare_two_symbols); - #ifdef DEBUG + qsort(symbols->symbols_arr, symbols->len, sizeof(char *), + compare_two_symbols); +#ifdef DEBUG printf("------ print after sort ------\n"); print_symbols_arr(symbols); - #endif +#endif size_t i; - int r; // response from hashmap get and put + int r; // response from hashmap get and put for (i = 0; i < symbols->len; i++) { - char* symbol_curr = symbols->symbols_arr[i]; + + char *symbol_curr = symbols->symbols_arr[i]; // get first character from symbol_curr char first_character[2]; first_character[0] = symbol_curr[0]; first_character[1] = '\0'; - #ifdef DEBUG - printf("****** Current symbol is %s, its first character is %s ******\n", symbol_curr, first_character); - #endif +#ifdef DEBUG + printf("****** Current symbol is %s, its first character is %s ******\n", + symbol_curr, first_character); +#endif // key would be the first character of symbol_curr // the value would be an array of chars - struct symbols_arr* associated_symbols; - r = hashmap_get(char_to_symbols, first_character, (any_t*)&associated_symbols); + struct symbols_arr *associated_symbols; + r = hashmap_get(char_to_symbols, first_character, + (any_t *)&associated_symbols); if (!r) { - // append current symbol to existing array - #ifdef DEBUG - printf("****** First character %s is already in hashmap ******\n", first_character); - #endif - if(!add_element_to_symbols_arr(associated_symbols, symbol_curr, strlen(symbol_curr) + 1)) { + +// append current symbol to existing array +#ifdef DEBUG + printf("****** First character %s is already in hashmap ******\n", + first_character); +#endif + if (!add_element_to_symbols_arr(associated_symbols, symbol_curr, + strlen(symbol_curr) + 1)) { + free_hashmap(char_to_symbols, &free_array_of_chars); return NULL; + } - } - else { - // start a new symbols_arr - #ifdef DEBUG - printf("****** First character %s is not in hashmap ******\n", first_character); - #endif - struct symbols_arr* new_associated_symbols = create_array_of_chars(); - strncpy(first_chars->symbols_arr[first_chars->len], first_character, 2); // 2 because one character plus the NULL byte - add_element_to_symbols_arr(new_associated_symbols, symbol_curr, strlen(symbol_curr) + 1); - r = hashmap_put(char_to_symbols, first_chars->symbols_arr[first_chars->len], new_associated_symbols); + + } else { + +// start a new symbols_arr +#ifdef DEBUG + printf("****** First character %s is not in hashmap ******\n", + first_character); +#endif + struct symbols_arr *new_associated_symbols = create_array_of_chars(); + strncpy(first_chars->symbols_arr[first_chars->len], first_character, + 2); // 2 because one character plus the NULL byte + add_element_to_symbols_arr(new_associated_symbols, symbol_curr, + strlen(symbol_curr) + 1); + r = hashmap_put(char_to_symbols, + first_chars->symbols_arr[first_chars->len], + new_associated_symbols); first_chars->len++; - #ifdef DEBUG +#ifdef DEBUG if (r) { + printf("hashmap put failed\n"); - } - else { + + } else { + printf("hashmap put succeeded\n"); + } - #endif + +#endif + } + } + printf("****** Testing ******\n"); - struct symbols_arr* tmp_arr; - char str[] = "i"; - int t = hashmap_get(char_to_symbols, str, (any_t *)&tmp_arr); - if (!t) - print_symbols_arr(tmp_arr); + struct symbols_arr *tmp_arr; + char str[] = "i"; + int t = hashmap_get(char_to_symbols, str, (any_t *)&tmp_arr); + if (!t) print_symbols_arr(tmp_arr); return char_to_symbols; + } -struct symbols_arr* create_array_of_chars() { - struct symbols_arr* ret = (struct symbols_arr*)malloc(sizeof(struct symbols_arr)); - ret->len = 0; - ret->symbols_arr = (char **)malloc(MAX_TERMINAL_NUMS * sizeof(char*)); +struct symbols_arr *create_array_of_chars() { + + struct symbols_arr *ret = + (struct symbols_arr *)malloc(sizeof(struct symbols_arr)); + ret->len = 0; + ret->symbols_arr = (char **)malloc(MAX_TERMINAL_NUMS * sizeof(char *)); size_t i; for (i = 0; i < MAX_TERMINAL_NUMS; i++) { + ret->symbols_arr[i] = (char *)calloc(MAX_TERMINAL_LENGTH, sizeof(char)); + } + return ret; + } // map a symbol to a list of (state, trigger_idx) -map_t create_pda_hashmap(state* pda, struct symbols_arr* symbols_arr) { - int state_idx, trigger_idx, r; // r is the return result for hashmap operation +map_t create_pda_hashmap(state *pda, struct symbols_arr *symbols_arr) { + + int state_idx, trigger_idx, + r; // r is the return result for hashmap operation map_t m = hashmap_new(); // iterate over pda for (state_idx = 0; state_idx < numstates; state_idx++) { - #ifdef DEBUG + +#ifdef DEBUG printf("------ The state idx is %d ------\n", state_idx); - #endif +#endif if (state_idx == final_state) continue; - state* state_curr = pda + state_idx; - for (trigger_idx = 0; trigger_idx < state_curr->trigger_len; trigger_idx++) { - #ifdef DEBUG + state *state_curr = pda + state_idx; + for (trigger_idx = 0; trigger_idx < state_curr->trigger_len; + trigger_idx++) { + +#ifdef DEBUG printf("------ The trigger idx is %d ------\n", trigger_idx); - #endif - trigger* trigger_curr = state_curr->ptr + trigger_idx; - char* symbol_curr = trigger_curr->term; - size_t symbol_len = trigger_curr->term_len; - struct terminal_arr* terminal_arr_curr; - r = hashmap_get(m, symbol_curr, (any_t*)&terminal_arr_curr); +#endif + trigger * trigger_curr = state_curr->ptr + trigger_idx; + char * symbol_curr = trigger_curr->term; + size_t symbol_len = trigger_curr->term_len; + struct terminal_arr *terminal_arr_curr; + r = hashmap_get(m, symbol_curr, (any_t *)&terminal_arr_curr); if (r) { + // the symbol is not in the map - if (!add_element_to_symbols_arr(symbols_arr, symbol_curr, symbol_len+1)) { + if (!add_element_to_symbols_arr(symbols_arr, symbol_curr, + symbol_len + 1)) { + // the number of symbols exceed maximual number free_hashmap(m, &free_terminal_arr); return NULL; + } - #ifdef DEBUG + +#ifdef DEBUG printf("Symbol %s is not in map\n", symbol_curr); - #endif - struct terminal_arr* new_terminal_arr = (struct terminal_arr*)malloc(sizeof(struct terminal_arr)); - new_terminal_arr->start = (struct terminal_meta*)calloc(numstates, sizeof(struct terminal_meta)); - #ifdef DEBUG +#endif + struct terminal_arr *new_terminal_arr = + (struct terminal_arr *)malloc(sizeof(struct terminal_arr)); + new_terminal_arr->start = (struct terminal_meta *)calloc( + numstates, sizeof(struct terminal_meta)); +#ifdef DEBUG printf("allocate new memory address %p\n", new_terminal_arr->start); - #endif +#endif new_terminal_arr->start->state_name = state_idx; new_terminal_arr->start->dest = trigger_curr->dest; new_terminal_arr->start->trigger_idx = trigger_idx; new_terminal_arr->len = 1; - #ifdef DEBUG - printf("Symbol %s is included in %zu edges\n", symbol_curr, new_terminal_arr->len); - #endif +#ifdef DEBUG + printf("Symbol %s is included in %zu edges\n", symbol_curr, + new_terminal_arr->len); +#endif r = hashmap_put(m, symbol_curr, new_terminal_arr); - #ifdef DEBUG +#ifdef DEBUG if (r) { + printf("hashmap put failed\n"); - } - else { + + } else { + printf("hashmap put succeeded\n"); + } - #endif - // if symbol not already in map, it's not in symbol_dict, simply add the symbol to the array + +#endif + // if symbol not already in map, it's not in symbol_dict, simply add the + // symbol to the array // TODO: need to initialize symbol dict (calloc) - } - else { - // the symbol is already in map - // append to terminal array - // no need to touch start - #ifdef DEBUG + + } else { + +// the symbol is already in map +// append to terminal array +// no need to touch start +#ifdef DEBUG printf("Symbol %s is in map\n", symbol_curr); - #endif - struct terminal_meta* modify = terminal_arr_curr->start + terminal_arr_curr->len; +#endif + struct terminal_meta *modify = + terminal_arr_curr->start + terminal_arr_curr->len; modify->state_name = state_idx; modify->trigger_idx = trigger_idx; modify->dest = trigger_curr->dest; terminal_arr_curr->len++; - #ifdef DEBUG - printf("Symbol %s is included in %zu edges\n", symbol_curr, terminal_arr_curr->len); - #endif - // if symbol already in map, it's already in symbol_dict as well, no work needs to be done +#ifdef DEBUG + printf("Symbol %s is included in %zu edges\n", symbol_curr, + terminal_arr_curr->len); +#endif + // if symbol already in map, it's already in symbol_dict as well, no + // work needs to be done + } } + } + return m; + } -void print_symbols_arr(struct symbols_arr* arr) { +void print_symbols_arr(struct symbols_arr *arr) { + size_t i; printf("("); for (i = 0; i < arr->len; i++) { + printf("%s", arr->symbols_arr[i]); if (i != arr->len - 1) printf(","); + } + printf(")\n"); + } void free_hashmap(map_t m, int (*f)(any_t, any_t)) { + if (!m) { + printf("m map is empty\n"); return; + } + int r = hashmap_iterate(m, f, NULL); - #ifdef DEBUG - if (!r) printf("free hashmap items successfully!\n"); - else printf("free hashmap items failed"); - #endif +#ifdef DEBUG + if (!r) + printf("free hashmap items successfully!\n"); + else + printf("free hashmap items failed"); +#endif hashmap_free(m); + } int free_array_of_chars(any_t placeholder, any_t item) { + if (!item) { + printf("item is empty\n"); return MAP_MISSING; + } - struct symbols_arr* arr = item; - size_t i; + + struct symbols_arr *arr = item; + size_t i; for (i = 0; i < MAX_TERMINAL_NUMS; i++) { + free(arr->symbols_arr[i]); + } + free(arr->symbols_arr); free(arr); return MAP_OK; + } -void free_pda(state* pda) { +void free_pda(state *pda) { + if (!pda) { + printf("pda is null\n"); return; + } + size_t i, j; for (i = 0; i < numstates; i++) { - state* state_curr = pda + i; + + state *state_curr = pda + i; for (j = 0; j < state_curr->trigger_len; j++) { - trigger* trigger_curr = state_curr->ptr + j; + + trigger *trigger_curr = state_curr->ptr + j; free(trigger_curr->id); free(trigger_curr->term); + } + free(state_curr->ptr); + } + free(pda); + } -int dfs(struct terminal_arr** tmp, const char* program, const size_t program_length, struct terminal_arr** res, size_t idx, int curr_state) { - if (*res) return 1; // 1 means successfully found a path +int dfs(struct terminal_arr **tmp, const char *program, + const size_t program_length, struct terminal_arr **res, size_t idx, + int curr_state) { + + if (*res) return 1; // 1 means successfully found a path if (idx == program_length) { + // test if the last terminal points to the final state if (curr_state != final_state) return 0; *res = *tmp; return 1; + } + if ((*tmp)->len == MAX_PROGRAM_WALK_LENGTH) { + printf("Reached maximum program walk length\n"); return 0; + } + char first_char[2]; - first_char[0] = program[idx]; // first character of program + first_char[0] = program[idx]; // first character of program first_char[1] = '\0'; - int r; - struct symbols_arr* matching_symbols; - r = hashmap_get(first_char_to_symbols_map, first_char, (any_t *)&matching_symbols); + int r; + struct symbols_arr *matching_symbols; + r = hashmap_get(first_char_to_symbols_map, first_char, + (any_t *)&matching_symbols); if (r) { - printf("No symbols match the current character, abort!"); // hopefully won't reach this state + + printf( + "No symbols match the current character, abort!"); // hopefully won't + // reach this state return 0; + } + size_t i; - bool matched = false; + bool matched = false; for (i = 0; i < matching_symbols->len; i++) { + if (matched) break; char *matching_symbol = matching_symbols->symbols_arr[i]; if (!strncmp(matching_symbol, program + idx, strlen(matching_symbol))) { + // there is a match matched = true; // find the possible paths of that symbol - struct terminal_arr* ta; + struct terminal_arr *ta; int r2 = hashmap_get(pda_map, matching_symbol, (any_t *)&ta); if (!r2) { + // the terminal is found in the dictionary size_t j; for (j = 0; j < ta->len; j++) { + int state_name = (ta->start + j)->state_name; if (state_name != curr_state) continue; size_t trigger_idx = (ta->start + j)->trigger_idx; - int dest = (ta->start + j)->dest; + int dest = (ta->start + j)->dest; (*tmp)->start[(*tmp)->len].state_name = state_name; (*tmp)->start[(*tmp)->len].trigger_idx = trigger_idx; (*tmp)->start[(*tmp)->len].dest = dest; (*tmp)->len++; - if (dfs(tmp, program, program_length, res, idx + strlen(matching_symbol), dest)) return 1; + if (dfs(tmp, program, program_length, res, + idx + strlen(matching_symbol), dest)) + return 1; (*tmp)->len--; + } - } - else { - printf("No path goes out of this symbol, abort!"); // hopefully won't reach this state + + } else { + + printf("No path goes out of this symbol, abort!"); // hopefully won't + // reach this state return 0; + } + } + } + return 0; /* 1. First extract the first character of the current program @@ -292,76 +414,102 @@ int dfs(struct terminal_arr** tmp, const char* program, const size_t program_len 5. Recursion 6. Pop the path from the terminal array 7. - If idx reaches end of program, set tmp to res - - If idx is not at the end and nothing matches, the current path is not working, simply return 0 + - If idx is not at the end and nothing matches, the current path is not + working, simply return 0 */ + } -Array* constructArray(struct terminal_arr* terminal_arr, state* pda) { - Array * res = (Array *)calloc(1, sizeof(Array)); +Array *constructArray(struct terminal_arr *terminal_arr, state *pda) { + + Array *res = (Array *)calloc(1, sizeof(Array)); initArray(res, INIT_SIZE); size_t i; - for (i = 0; i < terminal_arr->len; i ++) { - struct terminal_meta* curr = terminal_arr->start + i; - int state_name = curr->state_name; - int trigger_idx = curr->trigger_idx; + for (i = 0; i < terminal_arr->len; i++) { + + struct terminal_meta *curr = terminal_arr->start + i; + int state_name = curr->state_name; + int trigger_idx = curr->trigger_idx; // get the symbol from pda - state* state_curr = pda + state_name; - trigger* trigger_curr = state_curr->ptr + trigger_idx; - char *symbol_curr = trigger_curr->term; - size_t symbol_curr_len = trigger_curr->term_len; + state * state_curr = pda + state_name; + trigger *trigger_curr = state_curr->ptr + trigger_idx; + char * symbol_curr = trigger_curr->term; + size_t symbol_curr_len = trigger_curr->term_len; insertArray(res, state_name, symbol_curr, symbol_curr_len, trigger_idx); + } + return res; + } -Array* automaton_parser(const uint8_t *seed_fn) { - Array* parsed_res = NULL; - FILE* ptr; - ptr = fopen(seed_fn, "r"); - if (ptr == NULL) { - printf("file can't be opened \n"); - fclose(ptr); - return NULL; - } - char ch; - char program[MAX_PROGRAM_LENGTH]; - int i = 0; - bool program_too_long = false; - do { - if (i == MAX_PROGRAM_LENGTH) { - // the maximum program length is reached - printf("maximum program length is reached, give up the current seed\n"); - program_too_long = true; - break; - } - ch = fgetc(ptr); - program[i] = ch; - i ++; - } while (ch != EOF); - program[i-1] = '\0'; +Array *automaton_parser(const uint8_t *seed_fn) { + + Array *parsed_res = NULL; + FILE * ptr; + ptr = fopen(seed_fn, "r"); + if (ptr == NULL) { + + printf("file can't be opened \n"); fclose(ptr); - if ((i == 1 && program[0] == '\0') || program_too_long) return NULL; - struct terminal_arr* arr_holder; - struct terminal_arr* dfs_res = NULL; - arr_holder = (struct terminal_arr*)calloc(1, sizeof(struct terminal_arr)); - arr_holder->start = (struct terminal_meta*)calloc(MAX_PROGRAM_WALK_LENGTH, sizeof(struct terminal_meta)); - int dfs_success = dfs(&arr_holder, program, strlen(program), &dfs_res, 0, init_state); - // printf("*** return value %d *** \n", dfs_success); - if (dfs_success) { - parsed_res = constructArray(dfs_res, pda); + return NULL; + + } + + char ch; + char program[MAX_PROGRAM_LENGTH]; + int i = 0; + bool program_too_long = false; + do { + + if (i == MAX_PROGRAM_LENGTH) { + + // the maximum program length is reached + printf("maximum program length is reached, give up the current seed\n"); + program_too_long = true; + break; + } - free(arr_holder->start); - free(arr_holder); - return parsed_res; + + ch = fgetc(ptr); + program[i] = ch; + i++; + + } while (ch != EOF); + + program[i - 1] = '\0'; + fclose(ptr); + if ((i == 1 && program[0] == '\0') || program_too_long) return NULL; + struct terminal_arr *arr_holder; + struct terminal_arr *dfs_res = NULL; + arr_holder = (struct terminal_arr *)calloc(1, sizeof(struct terminal_arr)); + arr_holder->start = (struct terminal_meta *)calloc( + MAX_PROGRAM_WALK_LENGTH, sizeof(struct terminal_meta)); + int dfs_success = + dfs(&arr_holder, program, strlen(program), &dfs_res, 0, init_state); + // printf("*** return value %d *** \n", dfs_success); + if (dfs_success) { parsed_res = constructArray(dfs_res, pda); } + free(arr_holder->start); + free(arr_holder); + return parsed_res; + } // return 0 if fails // return 1 if succeeds -int add_element_to_symbols_arr(struct symbols_arr* symbols_arr, char* symbol, size_t symbol_len) { - if (symbols_arr->len >= MAX_TERMINAL_NUMS || symbol_len >= MAX_TERMINAL_LENGTH) { +int add_element_to_symbols_arr(struct symbols_arr *symbols_arr, char *symbol, + size_t symbol_len) { + + if (symbols_arr->len >= MAX_TERMINAL_NUMS || + symbol_len >= MAX_TERMINAL_LENGTH) { + return 0; + } + strncpy(symbols_arr->symbols_arr[symbols_arr->len], symbol, symbol_len); symbols_arr->len++; return 1; -} \ No newline at end of file + +} + diff --git a/custom_mutators/gramatron/automaton-parser.h b/custom_mutators/gramatron/automaton-parser.h index d67a1679..762415af 100644 --- a/custom_mutators/gramatron/automaton-parser.h +++ b/custom_mutators/gramatron/automaton-parser.h @@ -17,38 +17,41 @@ struct terminal_meta { int trigger_idx; int dest; -} ; +}; -// represents a set of edges +// represents a set of edges struct terminal_arr { - struct terminal_meta* start; - size_t len; + struct terminal_meta *start; + size_t len; -} ; +}; // essentially a string array struct symbols_arr { - char** symbols_arr; - size_t len; -} ; -struct symbols_arr* symbols; // symbols contain all the symbols in the language -map_t pda_map; // a map that maps each symbol in the language to a set of edges -struct symbols_arr* first_chars; // an array of first characters, only temperary array -map_t first_char_to_symbols_map; // a map that maps each first character to a set of symbols (the symbols are sorted in descending order) + char **symbols_arr; + size_t len; +}; +struct symbols_arr *symbols; // symbols contain all the symbols in the language +map_t pda_map; // a map that maps each symbol in the language to a set of edges +struct symbols_arr + * first_chars; // an array of first characters, only temperary array +map_t first_char_to_symbols_map; // a map that maps each first character to a + // set of symbols (the symbols are sorted in + // descending order) // freeing terminal arrays int free_terminal_arr(any_t placeholder, any_t item); -// return a map that maps each symbol in the language to a set of edges +// return a map that maps each symbol in the language to a set of edges // populate symbols_arr with all the symbols in the language -map_t create_pda_hashmap(state* pda, struct symbols_arr* symbols_arr); +map_t create_pda_hashmap(state *pda, struct symbols_arr *symbols_arr); // print the string array -void print_symbols_arr(struct symbols_arr* arr); +void print_symbols_arr(struct symbols_arr *arr); // free hashmap // the function pointer contains function to free the values in the hashmap @@ -58,17 +61,19 @@ void free_hashmap(map_t m, int (*f)(any_t, any_t)); int free_array_of_chars(any_t placeholder, any_t item); // free the pda -void free_pda(state* pda); +void free_pda(state *pda); // create a string array -struct symbols_arr* create_array_of_chars(); +struct symbols_arr *create_array_of_chars(); -map_t create_first_char_to_symbols_hashmap(struct symbols_arr *symbols, struct symbols_arr *first_chars); +map_t create_first_char_to_symbols_hashmap(struct symbols_arr *symbols, + struct symbols_arr *first_chars); // return the automaton represented by the seed -Array* automaton_parser(const uint8_t *seed_fn); +Array *automaton_parser(const uint8_t *seed_fn); -int add_element_to_symbols_arr(struct symbols_arr* symbols_arr, char* symbol, size_t symbol_len); +int add_element_to_symbols_arr(struct symbols_arr *symbols_arr, char *symbol, + size_t symbol_len); +#endif -#endif \ No newline at end of file diff --git a/custom_mutators/gramatron/gramfuzz-mutators.c b/custom_mutators/gramatron/gramfuzz-mutators.c index 0fc9c307..789a36fd 100644 --- a/custom_mutators/gramatron/gramfuzz-mutators.c +++ b/custom_mutators/gramatron/gramfuzz-mutators.c @@ -58,7 +58,8 @@ Array *performSpliceOne(Array *originput, IdxMap_new *statemap_orig, int length = utarray_len(stateptr); if (length) { - int *splice_idx = (int *)utarray_eltptr(stateptr, rand_below(global_afl, length)); + int *splice_idx = + (int *)utarray_eltptr(stateptr, rand_below(global_afl, length)); ip.orig_idx = *splice_idx; ip.splice_idx = x; utarray_push_back(pairs, &ip); diff --git a/custom_mutators/gramatron/gramfuzz.c b/custom_mutators/gramatron/gramfuzz.c index ccdbbe60..f25dfead 100644 --- a/custom_mutators/gramatron/gramfuzz.c +++ b/custom_mutators/gramatron/gramfuzz.c @@ -165,10 +165,11 @@ my_mutator_t *afl_custom_init(afl_state_t *afl, unsigned int seed) { pda = create_pda(automaton_file); symbols = create_array_of_chars(); - pda_map = create_pda_hashmap((struct state*)pda, symbols); + pda_map = create_pda_hashmap((struct state *)pda, symbols); print_symbols_arr(symbols); first_chars = create_array_of_chars(); - first_char_to_symbols_map = create_first_char_to_symbols_hashmap(symbols, first_chars); + first_char_to_symbols_map = + create_first_char_to_symbols_hashmap(symbols, first_chars); } else { @@ -287,25 +288,28 @@ u8 afl_custom_queue_new_entry(my_mutator_t * data, // filename_new_queue,filename_orig_queue,automaton_fn); if (filename_orig_queue) { + if (data->mutated_walk) { + write_input(data->mutated_walk, automaton_fn); - } - else { - Array* parsed_walk = automaton_parser(filename_new_queue); + + } else { + + Array *parsed_walk = automaton_parser(filename_new_queue); if (!parsed_walk) PFATAL("Parser unsuccessful on %s", filename_new_queue); write_input(parsed_walk, automaton_fn); free(parsed_walk->start); free(parsed_walk); + } } else { - // TODO: try to parse the input seeds here, if they can be parsed, then generate the corresponding automaton file - // if not, then generate a new input + // TODO: try to parse the input seeds here, if they can be parsed, then + // generate the corresponding automaton file if not, then generate a new + // input new_input = automaton_parser(filename_new_queue); - if (new_input == NULL) { - new_input = gen_input(pda, NULL); - } + if (new_input == NULL) { new_input = gen_input(pda, NULL); } write_input(new_input, automaton_fn); // Update the placeholder file @@ -346,13 +350,17 @@ u8 afl_custom_queue_new_entry(my_mutator_t * data, uint8_t afl_custom_queue_get(my_mutator_t *data, const uint8_t *filename) { // get the filename - u8 * automaton_fn = alloc_printf("%s.aut", filename); - // find the automaton file, if the automaton file cannot be found, do not fuzz the current entry on the queue + u8 *automaton_fn = alloc_printf("%s.aut", filename); + // find the automaton file, if the automaton file cannot be found, do not fuzz + // the current entry on the queue FILE *fp; fp = fopen(automaton_fn, "rb"); if (fp == NULL) { - printf("File '%s' does not exist, exiting. Would not fuzz current entry on the queue\n", automaton_fn); + printf( + "File '%s' does not exist, exiting. Would not fuzz current entry on " + "the queue\n", + automaton_fn); return 0; } @@ -456,7 +464,8 @@ void afl_custom_deinit(my_mutator_t *data) { free_hashmap(pda_map, &free_terminal_arr); free_hashmap(first_char_to_symbols_map, &free_array_of_chars); free_pda(pda); - free_array_of_chars(NULL, symbols); // free the array of symbols + free_array_of_chars(NULL, symbols); // free the array of symbols free_array_of_chars(NULL, first_chars); + } diff --git a/custom_mutators/gramatron/hashmap.c b/custom_mutators/gramatron/hashmap.c index 4f97e085..db4f9f98 100644 --- a/custom_mutators/gramatron/hashmap.c +++ b/custom_mutators/gramatron/hashmap.c @@ -171,6 +171,7 @@ unsigned long custom_crc32(const unsigned char *s, unsigned int len) { * Hashing function for a string */ unsigned int hashmap_hash_int(hashmap_map *m, char *keystring) { + unsigned int keystring_len = strlen(keystring); unsigned long key = custom_crc32((unsigned char *)(keystring), keystring_len); diff --git a/custom_mutators/gramatron/uthash.h b/custom_mutators/gramatron/uthash.h index 05c8abe6..93322d5b 100644 --- a/custom_mutators/gramatron/uthash.h +++ b/custom_mutators/gramatron/uthash.h @@ -127,6 +127,8 @@ typedef unsigned char uint8_t; #if HASH_NONFATAL_OOM /* malloc failures can be recovered from */ + #define IF_HASH_NONFATAL_OOM(x) x + #ifndef uthash_nonfatal_oom #define uthash_nonfatal_oom(obj) \ do { \ @@ -140,8 +142,6 @@ typedef unsigned char uint8_t; (oomed) = 1; \ \ } while (0) -\ - #define IF_HASH_NONFATAL_OOM(x) x #else /* malloc failures result in lost memory, hash tables are unusable */ @@ -156,11 +156,10 @@ typedef unsigned char uint8_t; #endif /* initial number of buckets */ -#define HASH_INITIAL_NUM_BUCKETS 32U /* initial number of buckets */ -#define HASH_INITIAL_NUM_BUCKETS_LOG2 \ - 5U /* lg2 of initial number of buckets \ - */ -#define HASH_BKT_CAPACITY_THRESH 10U /* expand when bucket count reaches */ +#define HASH_INITIAL_NUM_BUCKETS 32U /* initial number of buckets */ +#define HASH_INITIAL_NUM_BUCKETS_LOG2 5U /* lg2 of initial number of buckets \ + */ +#define HASH_BKT_CAPACITY_THRESH 10U /* expand when bucket count reaches */ /* calculate the element whose hash handle address is hhp */ #define ELMT_FROM_HH(tbl, hhp) ((void *)(((char *)(hhp)) - ((tbl)->hho))) @@ -647,7 +646,7 @@ typedef unsigned char uint8_t; HASH_FIND(hh, head, findstr, _uthash_hfstr_keylen, out); \ \ } while (0) -\ + #define HASH_ADD_STR(head, strfield, add) \ do { \ \ @@ -655,7 +654,7 @@ typedef unsigned char uint8_t; HASH_ADD(hh, head, strfield[0], _uthash_hastr_keylen, add); \ \ } while (0) -\ + #define HASH_REPLACE_STR(head, strfield, add, replaced) \ do { \ \ @@ -663,7 +662,7 @@ typedef unsigned char uint8_t; HASH_REPLACE(hh, head, strfield[0], _uthash_hrstr_keylen, add, replaced); \ \ } while (0) -\ + #define HASH_FIND_INT(head, findint, out) \ HASH_FIND(hh, head, findint, sizeof(int), out) #define HASH_ADD_INT(head, intfield, add) \ @@ -683,17 +682,17 @@ typedef unsigned char uint8_t; * isn't defined. */ #ifdef HASH_DEBUG - #define HASH_OOPS(...) \ - do { \ - \ - fprintf(stderr, __VA_ARGS__); \ - exit(-1); \ - \ - } while (0) -\ - #define HASH_FSCK(hh, head, where) \ + #define HASH_OOPS(...) \ do { \ \ + fprintf(stderr, __VA_ARGS__); \ + exit(-1); \ + \ + } while (0) \ + \ + \ + #define HASH_FSCK(hh, head, where) do { \ + \ struct UT_hash_handle *_thh; \ if (head) { \ \ @@ -759,7 +758,8 @@ typedef unsigned char uint8_t; \ } \ \ - } while (0) + } \ + while (0) #else #define HASH_FSCK(hh, head, where) @@ -1352,6 +1352,7 @@ typedef unsigned char uint8_t; \ } else if ((cmpfcn(DECLTYPE(head)( \ \ + \ ELMT_FROM_HH((head)->hh.tbl, _hs_p)), \ DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, \ _hs_q)))) <= 0) { \ -- cgit 1.4.1 From 0c3ba7d22719c694dafe1f053a9c8f8bad3993a7 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 07:23:06 -0400 Subject: clarity --- src/afl-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/afl-common.c b/src/afl-common.c index cbf20fba..b232b445 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -721,7 +721,7 @@ char *get_afl_env(char *env) { if (!be_quiet) { - OKF("Loaded environment variable %s with value %s", env, val); + OKF("Enabled environment variable %s with value %s", env, val); } -- cgit 1.4.1 From f23cac854aab2f7eb2ecb01e574571f00a0437fd Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 08:03:58 -0400 Subject: fix image build and push --- .github/workflows/build_aflplusplus_docker.yaml | 56 ++++++++++++------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build_aflplusplus_docker.yaml b/.github/workflows/build_aflplusplus_docker.yaml index a26f31d2..9ff8312a 100644 --- a/.github/workflows/build_aflplusplus_docker.yaml +++ b/.github/workflows/build_aflplusplus_docker.yaml @@ -3,37 +3,37 @@ name: Publish Docker Images on: push: branches: - - stable - - dev + - stable + - dev jobs: push_to_registry: name: Push Docker images to Dockerhub runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Login to Dockerhub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - - name: Publish aflpp ${{ github.ref }} to Registry - uses: docker/build-push-action@v2 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: aflplusplus/aflplusplus:${{ github.ref }} - if: "${{ github.ref }}" == "dev" - - name: Publish aflpp ${{ github.ref }} and latest to Registry - uses: docker/build-push-action@v2 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: aflplusplus/aflplusplus:${{ github.ref }},aflplusplus/aflplusplus:latest - if: "${{ github.ref }}" == "stable" + - uses: actions/checkout@master + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Dockerhub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + - name: Publish dev as dev to docker.io registry + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: aflplusplus/aflplusplus:${{ github.ref_name }} + if: ${{ github.ref_name == 'dev' }} + - name: Publish stable as stable and latest to docker.io registry + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: aflplusplus/aflplusplus:${{ github.ref_name }},aflplusplus/aflplusplus:latest + if: ${{ github.ref_name == 'stable' }} -- cgit 1.4.1 From b0e58baca2e5f67ce7304545e656868005ff73bd Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 08:21:25 -0400 Subject: add stable tag to docs --- README.md | 8 ++++---- docs/INSTALL.md | 4 ++-- docs/fuzzing_in_depth.md | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c3a627ec..d8498520 100644 --- a/README.md +++ b/README.md @@ -50,14 +50,14 @@ Here is some information to get you started: ## Building and installing AFL++ To have AFL++ easily available with everything compiled, pull the image directly -from the Docker Hub (available for x86_64 and arm64): +from the Docker Hub (available for both x86_64 and arm64): ```shell -docker pull aflplusplus/aflplusplus -docker run -ti -v /location/of/your/target:/src aflplusplus/aflplusplus +docker pull aflplusplus/aflplusplus:stable +docker run -ti -v /location/of/your/target:/src aflplusplus/aflplusplus:stable ``` -This image is automatically generated when a push to the stable repo happens +This image is automatically published when a push to the stable branch happens (see [branches](#branches)). If you use the command above, you will find your target source code in `/src` in the container. diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 754621b5..ac7b5486 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -8,8 +8,8 @@ hence afl-clang-lto is available) or just pull directly from the Docker Hub (for x86_64 and arm64): ```shell -docker pull aflplusplus/aflplusplus -docker run -ti -v /location/of/your/target:/src aflplusplus/aflplusplus +docker pull aflplusplus/aflplusplus:stable +docker run -ti -v /location/of/your/target:/src aflplusplus/aflplusplus:stable ``` This image is automatically generated when a push to the stable repo happens. diff --git a/docs/fuzzing_in_depth.md b/docs/fuzzing_in_depth.md index 2c27dfe1..d5fae0a6 100644 --- a/docs/fuzzing_in_depth.md +++ b/docs/fuzzing_in_depth.md @@ -47,7 +47,7 @@ tasks, fuzzing may put a strain on your hardware and on the OS. In particular: example, the following line will run a Docker container with all this preset: ```shell - # docker run -ti --mount type=tmpfs,destination=/ramdisk -e AFL_TMPDIR=/ramdisk aflplusplus/aflplusplus + # docker run -ti --mount type=tmpfs,destination=/ramdisk -e AFL_TMPDIR=/ramdisk aflplusplus/aflplusplus:stable ``` ## 1. Instrumenting the target -- cgit 1.4.1 From 51a88b17b318768b95442a74358f056768146d57 Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 08:31:37 -0400 Subject: add tagged releases --- .github/workflows/build_aflplusplus_docker.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/build_aflplusplus_docker.yaml b/.github/workflows/build_aflplusplus_docker.yaml index 9ff8312a..7245a84e 100644 --- a/.github/workflows/build_aflplusplus_docker.yaml +++ b/.github/workflows/build_aflplusplus_docker.yaml @@ -5,6 +5,8 @@ on: branches: - stable - dev + tags: + - '*' jobs: push_to_registry: @@ -37,3 +39,11 @@ jobs: push: true tags: aflplusplus/aflplusplus:${{ github.ref_name }},aflplusplus/aflplusplus:latest if: ${{ github.ref_name == 'stable' }} + - name: Publish tagged release to docker.io registry + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: aflplusplus/aflplusplus:${{ github.ref_name }} + if: ${{ github.ref_type == 'tag' }} -- cgit 1.4.1 From 85b1ce00a8c2c955f33d412d2f288807fe9b4d3e Mon Sep 17 00:00:00 2001 From: Ruben ten Hove Date: Sat, 18 Jun 2022 08:35:25 -0400 Subject: fully qualified names --- README.md | 4 ++-- docs/INSTALL.md | 4 ++-- docs/fuzzing_in_depth.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d8498520..91345d0c 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,8 @@ To have AFL++ easily available with everything compiled, pull the image directly from the Docker Hub (available for both x86_64 and arm64): ```shell -docker pull aflplusplus/aflplusplus:stable -docker run -ti -v /location/of/your/target:/src aflplusplus/aflplusplus:stable +docker pull docker.io/aflplusplus/aflplusplus:stable +docker run -ti -v /location/of/your/target:/src docker.io/aflplusplus/aflplusplus:stable ``` This image is automatically published when a push to the stable branch happens diff --git a/docs/INSTALL.md b/docs/INSTALL.md index ac7b5486..e29fca96 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -8,8 +8,8 @@ hence afl-clang-lto is available) or just pull directly from the Docker Hub (for x86_64 and arm64): ```shell -docker pull aflplusplus/aflplusplus:stable -docker run -ti -v /location/of/your/target:/src aflplusplus/aflplusplus:stable +docker pull docker.io/aflplusplus/aflplusplus:stable +docker run -ti -v /location/of/your/target:/src docker.io/aflplusplus/aflplusplus:stable ``` This image is automatically generated when a push to the stable repo happens. diff --git a/docs/fuzzing_in_depth.md b/docs/fuzzing_in_depth.md index d5fae0a6..8963c635 100644 --- a/docs/fuzzing_in_depth.md +++ b/docs/fuzzing_in_depth.md @@ -47,7 +47,7 @@ tasks, fuzzing may put a strain on your hardware and on the OS. In particular: example, the following line will run a Docker container with all this preset: ```shell - # docker run -ti --mount type=tmpfs,destination=/ramdisk -e AFL_TMPDIR=/ramdisk aflplusplus/aflplusplus:stable + # docker run -ti --mount type=tmpfs,destination=/ramdisk -e AFL_TMPDIR=/ramdisk docker.io/aflplusplus/aflplusplus:stable ``` ## 1. Instrumenting the target -- cgit 1.4.1 From eb37cec76ebf5d61bde96ff2993d3df3ef97f607 Mon Sep 17 00:00:00 2001 From: Joe Rozner Date: Sun, 19 Jun 2022 11:42:31 -0700 Subject: Update workflows to ubuntu 22.04 22.04 is the most recent LTS release and the official docker container is running on it. It probably makes sense to run the unit tests on that as well. --- .github/workflows/ci.yml | 2 +- .github/workflows/rust_custom_mutator.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 886148df..799b72e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: '${{ matrix.os }}' strategy: matrix: - os: [ubuntu-20.04, ubuntu-18.04] + os: [ubuntu-22.04, ubuntu-20.04, ubuntu-18.04] env: AFL_SKIP_CPUFREQ: 1 AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES: 1 diff --git a/.github/workflows/rust_custom_mutator.yml b/.github/workflows/rust_custom_mutator.yml index de2b184a..c279439e 100644 --- a/.github/workflows/rust_custom_mutator.yml +++ b/.github/workflows/rust_custom_mutator.yml @@ -15,7 +15,7 @@ jobs: working-directory: custom_mutators/rust strategy: matrix: - os: [ubuntu-20.04] + os: [ubuntu-22.04, ubuntu-20.04] steps: - uses: actions/checkout@v2 - name: Install Rust Toolchain -- cgit 1.4.1 From 1a4c0d2ecd428c8d3e6be8509738971861ddb5f2 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Mon, 20 Jun 2022 17:59:14 +0200 Subject: nits --- Android.bp | 1 + src/afl-cc.c | 2 +- src/afl-common.c | 10 +++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Android.bp b/Android.bp index ac1d5cb6..dfbfd281 100644 --- a/Android.bp +++ b/Android.bp @@ -76,6 +76,7 @@ cc_binary { srcs: [ "src/afl-fuzz*.c", "src/afl-common.c", + "src/afl-forkserver.c", "src/afl-sharedmem.c", "src/afl-forkserver.c", "src/afl-performance.c", diff --git a/src/afl-cc.c b/src/afl-cc.c index 2667ae28..4a56169f 100644 --- a/src/afl-cc.c +++ b/src/afl-cc.c @@ -396,7 +396,7 @@ static void edit_params(u32 argc, char **argv, char **envp) { snprintf(llvm_fullpath, sizeof(llvm_fullpath), "%s/clang", LLVM_BINDIR); else - snprintf(llvm_fullpath, sizeof(llvm_fullpath), CLANG_BIN); + snprintf(llvm_fullpath, sizeof(llvm_fullpath), "%s", CLANG_BIN); alt_cc = llvm_fullpath; } diff --git a/src/afl-common.c b/src/afl-common.c index b232b445..7f482e7d 100644 --- a/src/afl-common.c +++ b/src/afl-common.c @@ -25,8 +25,12 @@ #include #include -#define _GNU_SOURCE -#define __USE_GNU +#ifndef _GNU_SOURCE + #define _GNU_SOURCE +#endif +#ifndef __USE_GNU + #define __USE_GNU +#endif #include #include #include @@ -718,7 +722,7 @@ char *get_afl_env(char *env) { if ((val = getenv(env))) { if (*val) { - + if (!be_quiet) { OKF("Enabled environment variable %s with value %s", env, val); -- cgit 1.4.1 From 48c2d516899dcd77f1c167b195eb45b2a71cc303 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Mon, 27 Jun 2022 08:31:03 +0200 Subject: nits --- README.md | 4 +- .../gramatron/build_gramatron_mutator.sh | 4 +- custom_mutators/gramatron/gramfuzz-mutators.c | 3 +- custom_mutators/gramatron/gramfuzz.c | 48 ++-------------------- custom_mutators/gramatron/hashmap.c | 6 +-- custom_mutators/gramatron/testMakefile.mk | 3 -- custom_mutators/gramatron/uthash.h | 41 +++++++++--------- docs/INSTALL.md | 9 ++-- instrumentation/afl-llvm-common.cc | 4 +- test/test-frida-mode.sh | 2 +- 10 files changed, 39 insertions(+), 85 deletions(-) delete mode 100644 custom_mutators/gramatron/testMakefile.mk diff --git a/README.md b/README.md index 91345d0c..e851359e 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,8 @@ To have AFL++ easily available with everything compiled, pull the image directly from the Docker Hub (available for both x86_64 and arm64): ```shell -docker pull docker.io/aflplusplus/aflplusplus:stable -docker run -ti -v /location/of/your/target:/src docker.io/aflplusplus/aflplusplus:stable +docker pull aflplusplus/aflplusplus +docker run -ti -v /location/of/your/target:/src aflplusplus/aflplusplus ``` This image is automatically published when a push to the stable branch happens diff --git a/custom_mutators/gramatron/build_gramatron_mutator.sh b/custom_mutators/gramatron/build_gramatron_mutator.sh index 0638e3b2..9952e7f5 100755 --- a/custom_mutators/gramatron/build_gramatron_mutator.sh +++ b/custom_mutators/gramatron/build_gramatron_mutator.sh @@ -125,7 +125,7 @@ else } fi -test -f json-c/.git || { echo "[-] not checked out, please install git or check your internet connection." ; exit 1 ; } +test -d json-c/.git || { echo "[-] not checked out, please install git or check your internet connection." ; exit 1 ; } echo "[+] Got json-c." test -e json-c/.libs/libjson-c.a || { @@ -144,6 +144,6 @@ echo echo echo "[+] Json-c successfully prepared!" echo "[+] Builing gramatron now." -$CC -O3 -g -fPIC -Wno-unused-result -Wl,--allow-multiple-definition -I../../include -o gramatron.so -shared -I. -I/prg/dev/include gramfuzz.c gramfuzz-helpers.c gramfuzz-mutators.c gramfuzz-util.c hashmap.c automaton-parser.c ../../src/afl-performance.o json-c/.libs/libjson-c.a || exit 1 +$CC -O3 -g -fPIC -Wno-unused-result -Wl,--allow-multiple-definition -I../../include -o gramatron.so -shared -I. -I/prg/dev/include gramfuzz.c gramfuzz-helpers.c gramfuzz-mutators.c gramfuzz-util.c hashmap.c ../../src/afl-performance.o json-c/.libs/libjson-c.a || exit 1 echo echo "[+] gramatron successfully built!" diff --git a/custom_mutators/gramatron/gramfuzz-mutators.c b/custom_mutators/gramatron/gramfuzz-mutators.c index 789a36fd..0fc9c307 100644 --- a/custom_mutators/gramatron/gramfuzz-mutators.c +++ b/custom_mutators/gramatron/gramfuzz-mutators.c @@ -58,8 +58,7 @@ Array *performSpliceOne(Array *originput, IdxMap_new *statemap_orig, int length = utarray_len(stateptr); if (length) { - int *splice_idx = - (int *)utarray_eltptr(stateptr, rand_below(global_afl, length)); + int *splice_idx = (int *)utarray_eltptr(stateptr, rand_below(global_afl, length)); ip.orig_idx = *splice_idx; ip.splice_idx = x; utarray_push_back(pairs, &ip); diff --git a/custom_mutators/gramatron/gramfuzz.c b/custom_mutators/gramatron/gramfuzz.c index f25dfead..9c9dbb43 100644 --- a/custom_mutators/gramatron/gramfuzz.c +++ b/custom_mutators/gramatron/gramfuzz.c @@ -9,7 +9,6 @@ #include "afl-fuzz.h" #include "gramfuzz.h" -#include "automaton-parser.h" #define MUTATORS 4 // Specify the total number of mutators @@ -164,12 +163,6 @@ my_mutator_t *afl_custom_init(afl_state_t *afl, unsigned int seed) { if (automaton_file) { pda = create_pda(automaton_file); - symbols = create_array_of_chars(); - pda_map = create_pda_hashmap((struct state *)pda, symbols); - print_symbols_arr(symbols); - first_chars = create_array_of_chars(); - first_char_to_symbols_map = - create_first_char_to_symbols_hashmap(symbols, first_chars); } else { @@ -289,27 +282,11 @@ u8 afl_custom_queue_new_entry(my_mutator_t * data, if (filename_orig_queue) { - if (data->mutated_walk) { - - write_input(data->mutated_walk, automaton_fn); - - } else { - - Array *parsed_walk = automaton_parser(filename_new_queue); - if (!parsed_walk) PFATAL("Parser unsuccessful on %s", filename_new_queue); - write_input(parsed_walk, automaton_fn); - free(parsed_walk->start); - free(parsed_walk); - - } + write_input(data->mutated_walk, automaton_fn); } else { - // TODO: try to parse the input seeds here, if they can be parsed, then - // generate the corresponding automaton file if not, then generate a new - // input - new_input = automaton_parser(filename_new_queue); - if (new_input == NULL) { new_input = gen_input(pda, NULL); } + new_input = gen_input(pda, NULL); write_input(new_input, automaton_fn); // Update the placeholder file @@ -350,21 +327,7 @@ u8 afl_custom_queue_new_entry(my_mutator_t * data, uint8_t afl_custom_queue_get(my_mutator_t *data, const uint8_t *filename) { // get the filename - u8 *automaton_fn = alloc_printf("%s.aut", filename); - // find the automaton file, if the automaton file cannot be found, do not fuzz - // the current entry on the queue - FILE *fp; - fp = fopen(automaton_fn, "rb"); - if (fp == NULL) { - - printf( - "File '%s' does not exist, exiting. Would not fuzz current entry on " - "the queue\n", - automaton_fn); - return 0; - - } - + u8 * automaton_fn = alloc_printf("%s.aut", filename); IdxMap_new *statemap_ptr; terminal * term_ptr; int state; @@ -461,11 +424,6 @@ void afl_custom_deinit(my_mutator_t *data) { free(data->mutator_buf); free(data); - free_hashmap(pda_map, &free_terminal_arr); - free_hashmap(first_char_to_symbols_map, &free_array_of_chars); - free_pda(pda); - free_array_of_chars(NULL, symbols); // free the array of symbols - free_array_of_chars(NULL, first_chars); } diff --git a/custom_mutators/gramatron/hashmap.c b/custom_mutators/gramatron/hashmap.c index db4f9f98..09715b87 100644 --- a/custom_mutators/gramatron/hashmap.c +++ b/custom_mutators/gramatron/hashmap.c @@ -151,7 +151,7 @@ static unsigned long crc32_tab[] = { /* Return a 32-bit CRC of the contents of the buffer. */ -unsigned long custom_crc32(const unsigned char *s, unsigned int len) { +unsigned long crc32(const unsigned char *s, unsigned int len) { unsigned int i; unsigned long crc32val; @@ -172,9 +172,7 @@ unsigned long custom_crc32(const unsigned char *s, unsigned int len) { */ unsigned int hashmap_hash_int(hashmap_map *m, char *keystring) { - unsigned int keystring_len = strlen(keystring); - - unsigned long key = custom_crc32((unsigned char *)(keystring), keystring_len); + unsigned long key = crc32((unsigned char *)(keystring), strlen(keystring)); /* Robert Jenkins' 32 bit Mix Function */ key += (key << 12); diff --git a/custom_mutators/gramatron/testMakefile.mk b/custom_mutators/gramatron/testMakefile.mk deleted file mode 100644 index ff19826b..00000000 --- a/custom_mutators/gramatron/testMakefile.mk +++ /dev/null @@ -1,3 +0,0 @@ -test: test.c - gcc -g -fPIC -Wno-unused-result -Wl,--allow-multiple-definition -I../../include -o test -I. -I/prg/dev/include test.c gramfuzz-helpers.c gramfuzz-mutators.c gramfuzz-util.c hashmap.c ../../src/afl-performance.o json-c/.libs/libjson-c.a - diff --git a/custom_mutators/gramatron/uthash.h b/custom_mutators/gramatron/uthash.h index 93322d5b..05c8abe6 100644 --- a/custom_mutators/gramatron/uthash.h +++ b/custom_mutators/gramatron/uthash.h @@ -127,8 +127,6 @@ typedef unsigned char uint8_t; #if HASH_NONFATAL_OOM /* malloc failures can be recovered from */ - #define IF_HASH_NONFATAL_OOM(x) x - #ifndef uthash_nonfatal_oom #define uthash_nonfatal_oom(obj) \ do { \ @@ -142,6 +140,8 @@ typedef unsigned char uint8_t; (oomed) = 1; \ \ } while (0) +\ + #define IF_HASH_NONFATAL_OOM(x) x #else /* malloc failures result in lost memory, hash tables are unusable */ @@ -156,10 +156,11 @@ typedef unsigned char uint8_t; #endif /* initial number of buckets */ -#define HASH_INITIAL_NUM_BUCKETS 32U /* initial number of buckets */ -#define HASH_INITIAL_NUM_BUCKETS_LOG2 5U /* lg2 of initial number of buckets \ - */ -#define HASH_BKT_CAPACITY_THRESH 10U /* expand when bucket count reaches */ +#define HASH_INITIAL_NUM_BUCKETS 32U /* initial number of buckets */ +#define HASH_INITIAL_NUM_BUCKETS_LOG2 \ + 5U /* lg2 of initial number of buckets \ + */ +#define HASH_BKT_CAPACITY_THRESH 10U /* expand when bucket count reaches */ /* calculate the element whose hash handle address is hhp */ #define ELMT_FROM_HH(tbl, hhp) ((void *)(((char *)(hhp)) - ((tbl)->hho))) @@ -646,7 +647,7 @@ typedef unsigned char uint8_t; HASH_FIND(hh, head, findstr, _uthash_hfstr_keylen, out); \ \ } while (0) - +\ #define HASH_ADD_STR(head, strfield, add) \ do { \ \ @@ -654,7 +655,7 @@ typedef unsigned char uint8_t; HASH_ADD(hh, head, strfield[0], _uthash_hastr_keylen, add); \ \ } while (0) - +\ #define HASH_REPLACE_STR(head, strfield, add, replaced) \ do { \ \ @@ -662,7 +663,7 @@ typedef unsigned char uint8_t; HASH_REPLACE(hh, head, strfield[0], _uthash_hrstr_keylen, add, replaced); \ \ } while (0) - +\ #define HASH_FIND_INT(head, findint, out) \ HASH_FIND(hh, head, findint, sizeof(int), out) #define HASH_ADD_INT(head, intfield, add) \ @@ -682,17 +683,17 @@ typedef unsigned char uint8_t; * isn't defined. */ #ifdef HASH_DEBUG - #define HASH_OOPS(...) \ + #define HASH_OOPS(...) \ + do { \ + \ + fprintf(stderr, __VA_ARGS__); \ + exit(-1); \ + \ + } while (0) +\ + #define HASH_FSCK(hh, head, where) \ do { \ \ - fprintf(stderr, __VA_ARGS__); \ - exit(-1); \ - \ - } while (0) \ - \ - \ - #define HASH_FSCK(hh, head, where) do { \ - \ struct UT_hash_handle *_thh; \ if (head) { \ \ @@ -758,8 +759,7 @@ typedef unsigned char uint8_t; \ } \ \ - } \ - while (0) + } while (0) #else #define HASH_FSCK(hh, head, where) @@ -1352,7 +1352,6 @@ typedef unsigned char uint8_t; \ } else if ((cmpfcn(DECLTYPE(head)( \ \ - \ ELMT_FROM_HH((head)->hh.tbl, _hs_p)), \ DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, \ _hs_q)))) <= 0) { \ diff --git a/docs/INSTALL.md b/docs/INSTALL.md index e29fca96..41ec8561 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -8,11 +8,11 @@ hence afl-clang-lto is available) or just pull directly from the Docker Hub (for x86_64 and arm64): ```shell -docker pull docker.io/aflplusplus/aflplusplus:stable -docker run -ti -v /location/of/your/target:/src docker.io/aflplusplus/aflplusplus:stable +docker pull aflplusplus/aflplusplus: +docker run -ti -v /location/of/your/target:/src aflplusplus/aflplusplus ``` -This image is automatically generated when a push to the stable repo happens. +This image is automatically generated when a push to the stable branch happens. You will find your target source code in `/src` in the container. Note: you can also pull `aflplusplus/aflplusplus:dev` which is the most current @@ -21,6 +21,9 @@ development state of AFL++. If you want to build AFL++ yourself, you have many options. The easiest choice is to build and install everything: +NOTE: depending on your Debian/Ubuntu/Kali/... version replease `-12` with +whatever llvm version is available! + ```shell sudo apt-get update sudo apt-get install -y build-essential python3-dev automake cmake git flex bison libglib2.0-dev libpixman-1-dev python3-setuptools diff --git a/instrumentation/afl-llvm-common.cc b/instrumentation/afl-llvm-common.cc index 9483da83..5fcf27fb 100644 --- a/instrumentation/afl-llvm-common.cc +++ b/instrumentation/afl-llvm-common.cc @@ -291,7 +291,7 @@ void scanForDangerousFunctions(llvm::Module *M) { StringRef r_name = cast(r->getOperand(0))->getName(); if (!be_quiet) fprintf(stderr, - "Info: Found an ifunc with name %s that points to resolver " + "Note: Found an ifunc with name %s that points to resolver " "function %s, we will not instrument this, putting it into the " "block list.\n", ifunc_name.str().c_str(), r_name.str().c_str()); @@ -329,7 +329,7 @@ void scanForDangerousFunctions(llvm::Module *M) { if (!be_quiet) fprintf(stderr, - "Info: Found constructor function %s with prio " + "Note: Found constructor function %s with prio " "%u, we will not instrument this, putting it into a " "block list.\n", F->getName().str().c_str(), Priority); diff --git a/test/test-frida-mode.sh b/test/test-frida-mode.sh index 59b8e307..9e1f756d 100755 --- a/test/test-frida-mode.sh +++ b/test/test-frida-mode.sh @@ -62,7 +62,7 @@ test -e ../afl-frida-trace.so && { #else #fi export AFL_FRIDA_PERSISTENT_ADDR=0x`nm test-instr | grep -Ei "T _main|T main" | awk '{print $1}'` - $ECHO "Info: AFL_FRIDA_PERSISTENT_ADDR=$AFL_FRIDA_PERSISTENT_ADDR <= $(nm test-instr | grep "T main" | awk '{print $1}')" + $ECHO "Note: AFL_FRIDA_PERSISTENT_ADDR=$AFL_FRIDA_PERSISTENT_ADDR <= $(nm test-instr | grep "T main" | awk '{print $1}')" env|grep AFL_|sort file test-instr export AFL_DEBUG_CHILD=1 -- cgit 1.4.1 From 9a93688e3eb4c670dbbe4ef581d0868106d844fb Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Mon, 27 Jun 2022 08:32:06 +0200 Subject: nits --- custom_mutators/gramatron/automaton-parser.c | 515 --------------------------- custom_mutators/gramatron/automaton-parser.h | 79 ---- 2 files changed, 594 deletions(-) delete mode 100644 custom_mutators/gramatron/automaton-parser.c delete mode 100644 custom_mutators/gramatron/automaton-parser.h diff --git a/custom_mutators/gramatron/automaton-parser.c b/custom_mutators/gramatron/automaton-parser.c deleted file mode 100644 index 266f5a07..00000000 --- a/custom_mutators/gramatron/automaton-parser.c +++ /dev/null @@ -1,515 +0,0 @@ -#include "afl-fuzz.h" -#include "automaton-parser.h" - -int free_terminal_arr(any_t placeholder, any_t item) { - - struct terminal_arr *tmp = item; - free(tmp->start); - free(tmp); - return MAP_OK; - -} - -int compare_two_symbols(const void *a, const void *b) { - - char * a_char = *(char **)a; - char * b_char = *(char **)b; - size_t fa = strlen(a_char); - size_t fb = strlen(b_char); - if (fa > fb) - return -1; - else if (fa == fb) - return 0; - else - return 1; - -} - -// TODO: create a map -// key: first character of a symbol, value: a list of symbols that starts with -// key, the list is sorted in descending order of the symbol lengths -map_t create_first_char_to_symbols_hashmap(struct symbols_arr *symbols, - struct symbols_arr *first_chars) { - - map_t char_to_symbols = hashmap_new(); - // TODO: free the allocated map - // sort the symbol_dict in descending order of the symbol lengths - qsort(symbols->symbols_arr, symbols->len, sizeof(char *), - compare_two_symbols); -#ifdef DEBUG - printf("------ print after sort ------\n"); - print_symbols_arr(symbols); -#endif - size_t i; - int r; // response from hashmap get and put - for (i = 0; i < symbols->len; i++) { - - char *symbol_curr = symbols->symbols_arr[i]; - // get first character from symbol_curr - char first_character[2]; - first_character[0] = symbol_curr[0]; - first_character[1] = '\0'; -#ifdef DEBUG - printf("****** Current symbol is %s, its first character is %s ******\n", - symbol_curr, first_character); -#endif - // key would be the first character of symbol_curr - // the value would be an array of chars - struct symbols_arr *associated_symbols; - r = hashmap_get(char_to_symbols, first_character, - (any_t *)&associated_symbols); - if (!r) { - -// append current symbol to existing array -#ifdef DEBUG - printf("****** First character %s is already in hashmap ******\n", - first_character); -#endif - if (!add_element_to_symbols_arr(associated_symbols, symbol_curr, - strlen(symbol_curr) + 1)) { - - free_hashmap(char_to_symbols, &free_array_of_chars); - return NULL; - - } - - } else { - -// start a new symbols_arr -#ifdef DEBUG - printf("****** First character %s is not in hashmap ******\n", - first_character); -#endif - struct symbols_arr *new_associated_symbols = create_array_of_chars(); - strncpy(first_chars->symbols_arr[first_chars->len], first_character, - 2); // 2 because one character plus the NULL byte - add_element_to_symbols_arr(new_associated_symbols, symbol_curr, - strlen(symbol_curr) + 1); - r = hashmap_put(char_to_symbols, - first_chars->symbols_arr[first_chars->len], - new_associated_symbols); - first_chars->len++; -#ifdef DEBUG - if (r) { - - printf("hashmap put failed\n"); - - } else { - - printf("hashmap put succeeded\n"); - - } - -#endif - - } - - } - - printf("****** Testing ******\n"); - struct symbols_arr *tmp_arr; - char str[] = "i"; - int t = hashmap_get(char_to_symbols, str, (any_t *)&tmp_arr); - if (!t) print_symbols_arr(tmp_arr); - return char_to_symbols; - -} - -struct symbols_arr *create_array_of_chars() { - - struct symbols_arr *ret = - (struct symbols_arr *)malloc(sizeof(struct symbols_arr)); - ret->len = 0; - ret->symbols_arr = (char **)malloc(MAX_TERMINAL_NUMS * sizeof(char *)); - size_t i; - for (i = 0; i < MAX_TERMINAL_NUMS; i++) { - - ret->symbols_arr[i] = (char *)calloc(MAX_TERMINAL_LENGTH, sizeof(char)); - - } - - return ret; - -} - -// map a symbol to a list of (state, trigger_idx) -map_t create_pda_hashmap(state *pda, struct symbols_arr *symbols_arr) { - - int state_idx, trigger_idx, - r; // r is the return result for hashmap operation - map_t m = hashmap_new(); - // iterate over pda - for (state_idx = 0; state_idx < numstates; state_idx++) { - -#ifdef DEBUG - printf("------ The state idx is %d ------\n", state_idx); -#endif - if (state_idx == final_state) continue; - state *state_curr = pda + state_idx; - for (trigger_idx = 0; trigger_idx < state_curr->trigger_len; - trigger_idx++) { - -#ifdef DEBUG - printf("------ The trigger idx is %d ------\n", trigger_idx); -#endif - trigger * trigger_curr = state_curr->ptr + trigger_idx; - char * symbol_curr = trigger_curr->term; - size_t symbol_len = trigger_curr->term_len; - struct terminal_arr *terminal_arr_curr; - r = hashmap_get(m, symbol_curr, (any_t *)&terminal_arr_curr); - if (r) { - - // the symbol is not in the map - if (!add_element_to_symbols_arr(symbols_arr, symbol_curr, - symbol_len + 1)) { - - // the number of symbols exceed maximual number - free_hashmap(m, &free_terminal_arr); - return NULL; - - } - -#ifdef DEBUG - printf("Symbol %s is not in map\n", symbol_curr); -#endif - struct terminal_arr *new_terminal_arr = - (struct terminal_arr *)malloc(sizeof(struct terminal_arr)); - new_terminal_arr->start = (struct terminal_meta *)calloc( - numstates, sizeof(struct terminal_meta)); -#ifdef DEBUG - printf("allocate new memory address %p\n", new_terminal_arr->start); -#endif - new_terminal_arr->start->state_name = state_idx; - new_terminal_arr->start->dest = trigger_curr->dest; - new_terminal_arr->start->trigger_idx = trigger_idx; - new_terminal_arr->len = 1; -#ifdef DEBUG - printf("Symbol %s is included in %zu edges\n", symbol_curr, - new_terminal_arr->len); -#endif - r = hashmap_put(m, symbol_curr, new_terminal_arr); -#ifdef DEBUG - if (r) { - - printf("hashmap put failed\n"); - - } else { - - printf("hashmap put succeeded\n"); - - } - -#endif - // if symbol not already in map, it's not in symbol_dict, simply add the - // symbol to the array - // TODO: need to initialize symbol dict (calloc) - - } else { - -// the symbol is already in map -// append to terminal array -// no need to touch start -#ifdef DEBUG - printf("Symbol %s is in map\n", symbol_curr); -#endif - struct terminal_meta *modify = - terminal_arr_curr->start + terminal_arr_curr->len; - modify->state_name = state_idx; - modify->trigger_idx = trigger_idx; - modify->dest = trigger_curr->dest; - terminal_arr_curr->len++; -#ifdef DEBUG - printf("Symbol %s is included in %zu edges\n", symbol_curr, - terminal_arr_curr->len); -#endif - // if symbol already in map, it's already in symbol_dict as well, no - // work needs to be done - - } - - } - - } - - return m; - -} - -void print_symbols_arr(struct symbols_arr *arr) { - - size_t i; - printf("("); - for (i = 0; i < arr->len; i++) { - - printf("%s", arr->symbols_arr[i]); - if (i != arr->len - 1) printf(","); - - } - - printf(")\n"); - -} - -void free_hashmap(map_t m, int (*f)(any_t, any_t)) { - - if (!m) { - - printf("m map is empty\n"); - return; - - } - - int r = hashmap_iterate(m, f, NULL); -#ifdef DEBUG - if (!r) - printf("free hashmap items successfully!\n"); - else - printf("free hashmap items failed"); -#endif - hashmap_free(m); - -} - -int free_array_of_chars(any_t placeholder, any_t item) { - - if (!item) { - - printf("item is empty\n"); - return MAP_MISSING; - - } - - struct symbols_arr *arr = item; - size_t i; - for (i = 0; i < MAX_TERMINAL_NUMS; i++) { - - free(arr->symbols_arr[i]); - - } - - free(arr->symbols_arr); - free(arr); - return MAP_OK; - -} - -void free_pda(state *pda) { - - if (!pda) { - - printf("pda is null\n"); - return; - - } - - size_t i, j; - for (i = 0; i < numstates; i++) { - - state *state_curr = pda + i; - for (j = 0; j < state_curr->trigger_len; j++) { - - trigger *trigger_curr = state_curr->ptr + j; - free(trigger_curr->id); - free(trigger_curr->term); - - } - - free(state_curr->ptr); - - } - - free(pda); - -} - -int dfs(struct terminal_arr **tmp, const char *program, - const size_t program_length, struct terminal_arr **res, size_t idx, - int curr_state) { - - if (*res) return 1; // 1 means successfully found a path - if (idx == program_length) { - - // test if the last terminal points to the final state - if (curr_state != final_state) return 0; - *res = *tmp; - return 1; - - } - - if ((*tmp)->len == MAX_PROGRAM_WALK_LENGTH) { - - printf("Reached maximum program walk length\n"); - return 0; - - } - - char first_char[2]; - first_char[0] = program[idx]; // first character of program - first_char[1] = '\0'; - int r; - struct symbols_arr *matching_symbols; - r = hashmap_get(first_char_to_symbols_map, first_char, - (any_t *)&matching_symbols); - if (r) { - - printf( - "No symbols match the current character, abort!"); // hopefully won't - // reach this state - return 0; - - } - - size_t i; - bool matched = false; - for (i = 0; i < matching_symbols->len; i++) { - - if (matched) break; - char *matching_symbol = matching_symbols->symbols_arr[i]; - if (!strncmp(matching_symbol, program + idx, strlen(matching_symbol))) { - - // there is a match - matched = true; - // find the possible paths of that symbol - struct terminal_arr *ta; - int r2 = hashmap_get(pda_map, matching_symbol, (any_t *)&ta); - if (!r2) { - - // the terminal is found in the dictionary - size_t j; - for (j = 0; j < ta->len; j++) { - - int state_name = (ta->start + j)->state_name; - if (state_name != curr_state) continue; - size_t trigger_idx = (ta->start + j)->trigger_idx; - int dest = (ta->start + j)->dest; - (*tmp)->start[(*tmp)->len].state_name = state_name; - (*tmp)->start[(*tmp)->len].trigger_idx = trigger_idx; - (*tmp)->start[(*tmp)->len].dest = dest; - (*tmp)->len++; - if (dfs(tmp, program, program_length, res, - idx + strlen(matching_symbol), dest)) - return 1; - (*tmp)->len--; - - } - - } else { - - printf("No path goes out of this symbol, abort!"); // hopefully won't - // reach this state - return 0; - - } - - } - - } - - return 0; - /* - 1. First extract the first character of the current program - 2. Match the possible symbols of that program - 3. Find the possible paths of that symbol - 4. Add to temporary terminal array - 5. Recursion - 6. Pop the path from the terminal array - 7. - If idx reaches end of program, set tmp to res - - If idx is not at the end and nothing matches, the current path is not - working, simply return 0 - */ - -} - -Array *constructArray(struct terminal_arr *terminal_arr, state *pda) { - - Array *res = (Array *)calloc(1, sizeof(Array)); - initArray(res, INIT_SIZE); - size_t i; - for (i = 0; i < terminal_arr->len; i++) { - - struct terminal_meta *curr = terminal_arr->start + i; - int state_name = curr->state_name; - int trigger_idx = curr->trigger_idx; - // get the symbol from pda - state * state_curr = pda + state_name; - trigger *trigger_curr = state_curr->ptr + trigger_idx; - char * symbol_curr = trigger_curr->term; - size_t symbol_curr_len = trigger_curr->term_len; - insertArray(res, state_name, symbol_curr, symbol_curr_len, trigger_idx); - - } - - return res; - -} - -Array *automaton_parser(const uint8_t *seed_fn) { - - Array *parsed_res = NULL; - FILE * ptr; - ptr = fopen(seed_fn, "r"); - if (ptr == NULL) { - - printf("file can't be opened \n"); - fclose(ptr); - return NULL; - - } - - char ch; - char program[MAX_PROGRAM_LENGTH]; - int i = 0; - bool program_too_long = false; - do { - - if (i == MAX_PROGRAM_LENGTH) { - - // the maximum program length is reached - printf("maximum program length is reached, give up the current seed\n"); - program_too_long = true; - break; - - } - - ch = fgetc(ptr); - program[i] = ch; - i++; - - } while (ch != EOF); - - program[i - 1] = '\0'; - fclose(ptr); - if ((i == 1 && program[0] == '\0') || program_too_long) return NULL; - struct terminal_arr *arr_holder; - struct terminal_arr *dfs_res = NULL; - arr_holder = (struct terminal_arr *)calloc(1, sizeof(struct terminal_arr)); - arr_holder->start = (struct terminal_meta *)calloc( - MAX_PROGRAM_WALK_LENGTH, sizeof(struct terminal_meta)); - int dfs_success = - dfs(&arr_holder, program, strlen(program), &dfs_res, 0, init_state); - // printf("*** return value %d *** \n", dfs_success); - if (dfs_success) { parsed_res = constructArray(dfs_res, pda); } - free(arr_holder->start); - free(arr_holder); - return parsed_res; - -} - -// return 0 if fails -// return 1 if succeeds -int add_element_to_symbols_arr(struct symbols_arr *symbols_arr, char *symbol, - size_t symbol_len) { - - if (symbols_arr->len >= MAX_TERMINAL_NUMS || - symbol_len >= MAX_TERMINAL_LENGTH) { - - return 0; - - } - - strncpy(symbols_arr->symbols_arr[symbols_arr->len], symbol, symbol_len); - symbols_arr->len++; - return 1; - -} - diff --git a/custom_mutators/gramatron/automaton-parser.h b/custom_mutators/gramatron/automaton-parser.h deleted file mode 100644 index 762415af..00000000 --- a/custom_mutators/gramatron/automaton-parser.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _AUTOMATON_PARSER_H -#define _AUTOMATON_PARSER_H - -#define NUMINPUTS 500 -#define MAX_PROGRAM_LENGTH 20000 -#define MAX_PROGRAM_WALK_LENGTH 5000 -#define MAX_TERMINAL_NUMS 5000 -#define MAX_TERMINAL_LENGTH 1000 -#define MAX_PROGRAM_NAME_LENGTH 5000 - -#include "gramfuzz.h" - -// represents an edge in the FSA -struct terminal_meta { - - int state_name; - int trigger_idx; - int dest; - -}; - -// represents a set of edges -struct terminal_arr { - - struct terminal_meta *start; - size_t len; - -}; - -// essentially a string array -struct symbols_arr { - - char **symbols_arr; - size_t len; - -}; - -struct symbols_arr *symbols; // symbols contain all the symbols in the language -map_t pda_map; // a map that maps each symbol in the language to a set of edges -struct symbols_arr - * first_chars; // an array of first characters, only temperary array -map_t first_char_to_symbols_map; // a map that maps each first character to a - // set of symbols (the symbols are sorted in - // descending order) - -// freeing terminal arrays -int free_terminal_arr(any_t placeholder, any_t item); - -// return a map that maps each symbol in the language to a set of edges -// populate symbols_arr with all the symbols in the language -map_t create_pda_hashmap(state *pda, struct symbols_arr *symbols_arr); - -// print the string array -void print_symbols_arr(struct symbols_arr *arr); - -// free hashmap -// the function pointer contains function to free the values in the hashmap -void free_hashmap(map_t m, int (*f)(any_t, any_t)); - -// free string array -int free_array_of_chars(any_t placeholder, any_t item); - -// free the pda -void free_pda(state *pda); - -// create a string array -struct symbols_arr *create_array_of_chars(); - -map_t create_first_char_to_symbols_hashmap(struct symbols_arr *symbols, - struct symbols_arr *first_chars); - -// return the automaton represented by the seed -Array *automaton_parser(const uint8_t *seed_fn); - -int add_element_to_symbols_arr(struct symbols_arr *symbols_arr, char *symbol, - size_t symbol_len); - -#endif - -- cgit 1.4.1 From cfb0257c99fa8c9ec4a4a33980092d1afd580638 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Mon, 27 Jun 2022 08:37:21 +0200 Subject: nits --- docs/fuzzing_in_depth.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fuzzing_in_depth.md b/docs/fuzzing_in_depth.md index 8963c635..2c27dfe1 100644 --- a/docs/fuzzing_in_depth.md +++ b/docs/fuzzing_in_depth.md @@ -47,7 +47,7 @@ tasks, fuzzing may put a strain on your hardware and on the OS. In particular: example, the following line will run a Docker container with all this preset: ```shell - # docker run -ti --mount type=tmpfs,destination=/ramdisk -e AFL_TMPDIR=/ramdisk docker.io/aflplusplus/aflplusplus:stable + # docker run -ti --mount type=tmpfs,destination=/ramdisk -e AFL_TMPDIR=/ramdisk aflplusplus/aflplusplus ``` ## 1. Instrumenting the target -- cgit 1.4.1 From 88077d4136fe36942d28ba956aa8536feb717638 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Mon, 27 Jun 2022 08:44:35 +0200 Subject: prepare release --- README.md | 4 ++-- docs/Changelog.md | 6 ++++-- include/config.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e851359e..53b2b8d0 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ AFL++ logo -Release version: [4.00c](https://github.com/AFLplusplus/AFLplusplus/releases) +Release version: [4.01c](https://github.com/AFLplusplus/AFLplusplus/releases) -GitHub version: 4.01a +GitHub version: 4.02a Repository: [https://github.com/AFLplusplus/AFLplusplus](https://github.com/AFLplusplus/AFLplusplus) diff --git a/docs/Changelog.md b/docs/Changelog.md index 44939b16..737df7fa 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -8,8 +8,8 @@ Want to stay in the loop on major new features? Join our mailing list by sending a mail to . -### Version ++4.01a (dev) - - fix */build_...sh scripts to work outside of git +### Version ++4.01c (release) + - fixed */build_...sh scripts to work outside of git - new custom_mutator: libafl with token fuzzing :) - afl-fuzz: - when you just want to compile once and set CMPLOG, then just @@ -17,6 +17,8 @@ sending a mail to . CMPLOG. - new commandline options -g/G to set min/max length of generated fuzz inputs + - you can set the time for syncing to other fuzzer now with + AFL_SYNC_TIME - reintroduced AFL_PERSISTENT and AFL_DEFER_FORKSRV to allow persistent mode and manual forkserver support if these are not in the target binary (e.g. are in a shared library) diff --git a/include/config.h b/include/config.h index 9fc92b06..aefea9cd 100644 --- a/include/config.h +++ b/include/config.h @@ -26,7 +26,7 @@ /* Version string: */ // c = release, a = volatile github dev, e = experimental branch -#define VERSION "++4.01a" +#define VERSION "++4.01c" /****************************************************** * * -- cgit 1.4.1 From fd404194f27cde819cb63704c5aa808caee03755 Mon Sep 17 00:00:00 2001 From: Brenton Bostick Date: Mon, 27 Jun 2022 11:38:33 -0400 Subject: Update afl-system-config System Integration Protection -> System Integrity Protection --- afl-system-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afl-system-config b/afl-system-config index ef343704..f482e4fb 100755 --- a/afl-system-config +++ b/afl-system-config @@ -118,7 +118,7 @@ if [ "$PLATFORM" = "Darwin" ] ; then sudo launchctl unload -w ${SL}/LaunchDaemons/${PL}.Root.plist >/dev/null 2>&1 echo fi - echo It is recommended to disable System Integration Protection for increased performance. + echo It is recommended to disable System Integrity Protection for increased performance. echo DONE=1 fi -- cgit 1.4.1 From 6705953a491e43880c57aa670b475b52c716f216 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Tue, 28 Jun 2022 10:23:20 +0200 Subject: Python mutators: Gracious error handling for illegal return type (#1464) * python types error handling * reverted example change * more python * format --- .gitignore | 1 + src/afl-fuzz-python.c | 93 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 80 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 22ee6bf1..8b0f0a7f 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,4 @@ utils/persistent_mode/persistent_demo_new utils/persistent_mode/test-instr !coresight_mode !coresight_mode/coresight-trace +vuln_prog \ No newline at end of file diff --git a/src/afl-fuzz-python.c b/src/afl-fuzz-python.c index 65501c8c..5909cd52 100644 --- a/src/afl-fuzz-python.c +++ b/src/afl-fuzz-python.c @@ -28,6 +28,36 @@ /* Python stuff */ #ifdef USE_PYTHON +// Tries to cast a python bytearray or bytes to a char ptr +static inline bool py_bytes(PyObject *py_value, /* out */ char **bytes, + /* out */ size_t *size) { + + if (!py_value) { return false; } + + *bytes = PyByteArray_AsString(py_value); + if (*bytes) { + + // we got a bytearray + *size = PyByteArray_Size(py_value); + + } else { + + *bytes = PyBytes_AsString(py_value); + if (!*bytes) { + + // No valid type returned. + return false; + + } + + *size = PyBytes_Size(py_value); + + } + + return true; + +} + static void *unsupported(afl_state_t *afl, unsigned int seed) { (void)afl; @@ -93,12 +123,22 @@ static size_t fuzz_py(void *py_mutator, u8 *buf, size_t buf_size, u8 **out_buf, if (py_value != NULL) { - mutated_size = PyByteArray_Size(py_value); + char *bytes; + if (!py_bytes(py_value, &bytes, &mutated_size)) { + + FATAL("Python mutator fuzz() should return a bytearray or bytes"); + + } + + if (mutated_size) { + + *out_buf = afl_realloc(BUF_PARAMS(fuzz), mutated_size); + if (unlikely(!*out_buf)) { PFATAL("alloc"); } - *out_buf = afl_realloc(BUF_PARAMS(fuzz), mutated_size); - if (unlikely(!*out_buf)) { PFATAL("alloc"); } + memcpy(*out_buf, bytes, mutated_size); + + } - memcpy(*out_buf, PyByteArray_AsString(py_value), mutated_size); Py_DECREF(py_value); return mutated_size; @@ -625,7 +665,7 @@ s32 post_trim_py(void *py_mutator, u8 success) { size_t trim_py(void *py_mutator, u8 **out_buf) { PyObject *py_args, *py_value; - size_t ret; + size_t trimmed_size; py_args = PyTuple_New(0); py_value = PyObject_CallObject( @@ -634,10 +674,21 @@ size_t trim_py(void *py_mutator, u8 **out_buf) { if (py_value != NULL) { - ret = PyByteArray_Size(py_value); - *out_buf = afl_realloc(BUF_PARAMS(trim), ret); - if (unlikely(!*out_buf)) { PFATAL("alloc"); } - memcpy(*out_buf, PyByteArray_AsString(py_value), ret); + char *bytes; + if (!py_bytes(py_value, &bytes, &trimmed_size)) { + + FATAL("Python mutator fuzz() should return a bytearray"); + + } + + if (trimmed_size) { + + *out_buf = afl_realloc(BUF_PARAMS(trim), trimmed_size); + if (unlikely(!*out_buf)) { PFATAL("alloc"); } + memcpy(*out_buf, bytes, trimmed_size); + + } + Py_DECREF(py_value); } else { @@ -647,7 +698,7 @@ size_t trim_py(void *py_mutator, u8 **out_buf) { } - return ret; + return trimmed_size; } @@ -692,7 +743,13 @@ size_t havoc_mutation_py(void *py_mutator, u8 *buf, size_t buf_size, if (py_value != NULL) { - mutated_size = PyByteArray_Size(py_value); + char *bytes; + if (!py_bytes(py_value, &bytes, &mutated_size)) { + + FATAL("Python mutator fuzz() should return a bytearray"); + + } + if (mutated_size <= buf_size) { /* We reuse the input buf here. */ @@ -706,8 +763,6 @@ size_t havoc_mutation_py(void *py_mutator, u8 *buf, size_t buf_size, } - memcpy(*out_buf, PyByteArray_AsString(py_value), mutated_size); - Py_DECREF(py_value); return mutated_size; @@ -762,7 +817,17 @@ const char *introspection_py(void *py_mutator) { } else { - return PyByteArray_AsString(py_value); + char * ret; + size_t len; + if (!py_bytes(py_value, &ret, &len)) { + + FATAL( + "Python mutator introspection call returned illegal type (expected " + "bytes or bytearray)"); + + } + + return ret; } -- cgit 1.4.1 From bb509765dfb96b38d5ed781843bfca1660ed9bf5 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Tue, 28 Jun 2022 11:45:22 +0200 Subject: added back missing memcpy to python mutators --- src/afl-fuzz-python.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/afl-fuzz-python.c b/src/afl-fuzz-python.c index 5909cd52..0231d2cd 100644 --- a/src/afl-fuzz-python.c +++ b/src/afl-fuzz-python.c @@ -763,6 +763,8 @@ size_t havoc_mutation_py(void *py_mutator, u8 *buf, size_t buf_size, } + if (mutated_size) { memcpy(*out_buf, bytes, mutated_size); } + Py_DECREF(py_value); return mutated_size; -- cgit 1.4.1 From 92352951d7a8485bd2413009fcd052e85dc398fb Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Tue, 28 Jun 2022 11:52:05 +0200 Subject: nits --- TODO.md | 1 + src/afl-fuzz.c | 1 + 2 files changed, 2 insertions(+) diff --git a/TODO.md b/TODO.md index 99d2c419..c64c1236 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,7 @@ ## Should + - makefiles should show provide a build summary success/failure - better documentation for custom mutators - better autodetection of shifting runtime timeout values - Update afl->pending_not_fuzzed for MOpt diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c index 7c33ba29..b23cef37 100644 --- a/src/afl-fuzz.c +++ b/src/afl-fuzz.c @@ -296,6 +296,7 @@ static void usage(u8 *argv0, int more_help) { " Supported formats are: 'dogstatsd', 'librato',\n" " 'signalfx' and 'influxdb'\n" "AFL_SYNC_TIME: sync time between fuzzing instances (in minutes)\n" + "AFL_NO_CRASH_README: do not create a README in the crashes directory\n" "AFL_TESTCACHE_SIZE: use a cache for testcases, improves performance (in MB)\n" "AFL_TMPDIR: directory to use for input file generation (ramdisk recommended)\n" "AFL_EARLY_FORKSERVER: force an early forkserver in an afl-clang-fast/\n" -- cgit 1.4.1