Skip to content

Commit

Permalink
Add utility functions for mutator's "propose change" opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
atrosinenko committed Nov 26, 2023
1 parent 1ba3193 commit e254df6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions runtime/common/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,16 @@ void res_mark_consumed_reference(struct fuzzer_state *state,
unsigned offset = res_get_cur_offset(state) - id_bytes;
mutator_ref_resource(kind, id, id_bytes, offset);
}

void res_propose_change_here(struct fuzzer_state *state,
uint64_t replacement, unsigned size) {
unsigned offset = res_get_cur_offset(state) - size;
mutator_propose_change(offset, replacement, size);
}

void res_propose_change_if_different(struct fuzzer_state *state, unsigned offset,
uint64_t replacement, unsigned size) {
void *current_data = &state->constant_state.input_buffer[offset];
if (memcmp(&current_data, &replacement, size))
mutator_propose_change(offset, replacement, size);
}
10 changes: 10 additions & 0 deletions runtime/include/kbdysch/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ void res_mark_section_start(struct fuzzer_state *state);
void res_mark_consumed_reference(struct fuzzer_state *state,
int kind, int id, unsigned id_bytes);

/**
* Utility function for mutator interface: call it right after
* reading the data to be patched.
*/
void res_propose_change_here(struct fuzzer_state *state,
uint64_t replacement, unsigned size);

void res_propose_change_if_different(struct fuzzer_state *state, unsigned offset,
uint64_t replacement, unsigned size);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit e254df6

Please sign in to comment.