Skip to content

Commit

Permalink
Mutator: improve fatal error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
atrosinenko committed Jan 5, 2024
1 parent 6762f41 commit 1a62750
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
9 changes: 2 additions & 7 deletions runtime/mutators/afl-generic-mutator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ DECLARE_INT_KNOB_DEF(num_best_effort_iterations,

using namespace kbdysch::mutator;

#ifndef NDEBUG
// Print a better message.
#define abort() assert(0)
#endif

struct mutator_state {
mutator_state();

Expand Down Expand Up @@ -219,7 +214,7 @@ size_t afl_custom_fuzz(void *data, uint8_t *buf, size_t buf_size, uint8_t **out_
ERR("Trying to save log...\n");
if (!save_log_from_shm(state, state->input.as_data(), "best effort mode")) {
state->create_debug_dump();
abort();
FATAL("Cannot save log (input length = %zu)", state->input.size());
}
accumulate_important_data(state);
state->current_journal.load_journal(state->input.as_data());
Expand All @@ -228,7 +223,7 @@ size_t afl_custom_fuzz(void *data, uint8_t *buf, size_t buf_size, uint8_t **out_
ERR("Trying to save log as-is...\n");
if (!save_log_from_shm(state, buffer_ref(), "best effort mode")) {
state->create_debug_dump();
abort();
FATAL("Cannot save log (input length = %zu)", state->input.size());
}
accumulate_important_data(state);
state->record_log_next_action = mutator_state::RECORD_LOG_NONE;
Expand Down
12 changes: 8 additions & 4 deletions runtime/mutators/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ FILE *create_temp_file(const char *prefix, const char *suffix);
#define DECL_WITH_TYPE(type, new_name, ptr) \
type *new_name = (type *)(ptr)

#define FATAL(fmt, ...) \
do { \
fprintf(stderr, "MUTATOR: %s: %d: " fmt, __FILE__, __LINE__, __VA_ARGS__); \
abort(); \
#define FATAL(fmt, ...) \
do { \
fprintf(stderr, "\n\n"); /* account for AFL's own UI. */ \
fprintf(stderr, "MUTATOR FATAL ERROR at %s:%d\n", __FILE__, __LINE__); \
fprintf(stderr, "MESSAGE: " fmt, __VA_ARGS__); \
abort(); \
} while (0)

#define FATAL_NOT_IMPLEMENTED(what) FATAL("Not implemented: %s", (what))

#define ERR(...) \
do { \
if (kbdysch::mutator::error_log) \
Expand Down
4 changes: 2 additions & 2 deletions runtime/mutators/mutations.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class mutation_strategy {
// Reimplement if needs_add_buf() returns false
virtual void render_next_mutation(test_case_storage &output,
buffer_ref input, journal_data &input_journal) {
abort();
FATAL_NOT_IMPLEMENTED("render_next_mutation (simple)");
}

// Reimplement if needs_add_buf() returns true
virtual void render_next_mutation(test_case_storage &output,
buffer_ref input, journal_data &input_journal,
buffer_ref add_buf, journal_data &add_journal) {
abort();
FATAL_NOT_IMPLEMENTED("render_next_mutation (with extra input)");
}

virtual ~mutation_strategy() {}
Expand Down
2 changes: 1 addition & 1 deletion runtime/mutators/variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class success_rate_variable : public variable {

protected:
void print_scalar(std::ostringstream &stream, unsigned subscript) override {
abort(); // Not implemented
FATAL_NOT_IMPLEMENTED("print_scalar");
}

private:
Expand Down

0 comments on commit 1a62750

Please sign in to comment.