diff options
author | arnow117 <arnow117@163.com> | 2019-04-09 05:14:11 +0800 |
---|---|---|
committer | arnow117 <arnow117@163.com> | 2019-04-09 05:14:11 +0800 |
commit | c7566f6a86ec3197dc9fadd099708b9aa950838b (patch) | |
tree | dfd5e57434a8e6ebf4da2c397c0233b2b0d2328b /input.c | |
parent | 868dccfed95dcbbaf7840683c4e9ca466be7bb9c (diff) | |
download | honggfuzz-c7566f6a86ec3197dc9fadd099708b9aa950838b.tar.gz |
add support for external command mutating files which have effective coverage feedback
Diffstat (limited to 'input.c')
-rw-r--r-- | input.c | 42 |
1 files changed, 38 insertions, 4 deletions
@@ -311,7 +311,7 @@ bool input_parseBlacklist(honggfuzz_t* hfuzz) { return true; } -bool input_prepareDynamicInput(run_t* run) { +bool input_prepareDynamicInput(run_t* run, bool need_mangele) { { MX_SCOPED_RWLOCK_READ(&run->global->io.dynfileq_mutex); @@ -332,12 +332,13 @@ bool input_prepareDynamicInput(run_t* run) { input_setSize(run, run->dynfileqCurrent->size); memcpy(run->dynamicFile, run->dynfileqCurrent->data, run->dynfileqCurrent->size); - mangle_mangleContent(run); + if (need_mangele) + mangle_mangleContent(run); return true; } -bool input_prepareStaticFile(run_t* run, bool rewind) { +bool input_prepareStaticFile(run_t* run, bool rewind, bool need_mangele) { char fname[PATH_MAX]; if (!input_getNext(run, fname, /* rewind= */ rewind)) { return false; @@ -352,7 +353,8 @@ bool input_prepareStaticFile(run_t* run, bool rewind) { } input_setSize(run, fileSz); - mangle_mangleContent(run); + if (need_mangele) + mangle_mangleContent(run); return true; } @@ -421,3 +423,35 @@ bool input_postProcessFile(run_t* run) { input_setSize(run, (size_t)sz); return true; } + +bool input_feedbackMutateFile(run_t* run) { + int fd = + files_writeBufToTmpFile(run->global->io.workDir, run->dynamicFile, run->dynamicFileSz, 0); + if (fd == -1) { + LOG_E("Couldn't write input file to a temporary buffer"); + return false; + } + defer { + close(fd); + }; + + char fname[PATH_MAX]; + snprintf(fname, sizeof(fname), "/dev/fd/%d", fd); + + const char* const argv[] = {run->global->exe.feedbackMutateCommand, fname, NULL}; + if (subproc_System(run, argv) != 0) { + LOG_E("Subprocess '%s' returned abnormally", run->global->exe.feedbackMutateCommand); + return false; + } + LOG_D("Subporcess '%s' finished with success", run->global->exe.externalCommand); + + input_setSize(run, run->global->mutate.maxFileSz); + ssize_t sz = files_readFromFdSeek(fd, run->dynamicFile, run->global->mutate.maxFileSz, 0); + if (sz == -1) { + LOG_E("Couldn't read file from fd=%d", fd); + return false; + } + + input_setSize(run, (size_t)sz); + return true; +}
\ No newline at end of file |