aboutsummaryrefslogtreecommitdiff
path: root/src/afl-fuzz-init.c
diff options
context:
space:
mode:
authorAndrea Fioraldi <andreafioraldi@gmail.com>2020-04-03 09:39:12 +0200
committerAndrea Fioraldi <andreafioraldi@gmail.com>2020-04-03 09:39:12 +0200
commit8610b0e40677846ba65de55fcaedd2ebee66a511 (patch)
treef5b6409fe840ac69417e348795b69cbeb0a072fc /src/afl-fuzz-init.c
parentffb4767fc1adf2383173e5655d4f1fcf7e0982b6 (diff)
parent97cae2df9975589eb05a543f92c6ba232242fd7b (diff)
downloadafl++-8610b0e40677846ba65de55fcaedd2ebee66a511.tar.gz
Merge branch 'dev' of github.com:vanhauser-thc/AFLplusplus into dev
Diffstat (limited to 'src/afl-fuzz-init.c')
-rw-r--r--src/afl-fuzz-init.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c
index 038c4393..e2495524 100644
--- a/src/afl-fuzz-init.c
+++ b/src/afl-fuzz-init.c
@@ -76,21 +76,16 @@ void bind_to_free_cpu(afl_state_t *afl) {
while ((de = readdir(d))) {
- u8 * fn;
+ u8 fn[PATH_MAX];
FILE *f;
u8 tmp[MAX_LINE];
u8 has_vmsize = 0;
if (!isdigit(de->d_name[0])) continue;
- fn = alloc_printf("/proc/%s/status", de->d_name);
+ snprintf(fn, PATH_MAX, "/proc/%s/status", de->d_name);
- if (!(f = fopen(fn, "r"))) {
-
- ck_free(fn);
- continue;
-
- }
+ if (!(f = fopen(fn, "r"))) { continue; }
while (fgets(tmp, MAX_LINE, f)) {
@@ -111,7 +106,6 @@ void bind_to_free_cpu(afl_state_t *afl) {
}
- ck_free(fn);
fclose(f);
}
@@ -276,7 +270,9 @@ void setup_post(afl_state_t *afl) {
void *dh;
u8 * fn = afl->afl_env.afl_post_library;
+ u8 tbuf[6];
u32 tlen = 6;
+ strncpy(tbuf, "hello", tlen);
if (!fn) return;
@@ -287,10 +283,20 @@ void setup_post(afl_state_t *afl) {
afl->post_handler = dlsym(dh, "afl_postprocess");
if (!afl->post_handler) FATAL("Symbol 'afl_postprocess' not found.");
+ afl->post_init = dlsym(dh, "afl_postprocess_init");
+ if (!afl->post_init) FATAL("Symbol 'afl_postprocess_init' not found.");
+ afl->post_deinit = dlsym(dh, "afl_postprocess_deinit");
+ if (!afl->post_deinit) FATAL("Symbol 'afl_postprocess_deinit' not found.");
/* Do a quick test. It's better to segfault now than later =) */
- afl->post_handler("hello", &tlen);
+ u8 *post_buf = NULL;
+ afl->post_data = afl->post_init(afl);
+ if (!afl->post_data) FATAL("Could not initialize post handler.");
+
+ size_t post_len = afl->post_handler(afl->post_data, tbuf, tlen, &post_buf);
+ if (!post_len || !post_buf)
+ SAYF("Empty return in test post handler for buf=\"hello\\0\".");
OKF("Postprocessor installed successfully.");
@@ -369,9 +375,10 @@ void read_testcases(afl_state_t *afl) {
struct stat st;
+ u8 dfn[PATH_MAX];
+ snprintf(dfn, PATH_MAX, "%s/.state/deterministic_done/%s", afl->in_dir,
+ nl[i]->d_name);
u8 *fn2 = alloc_printf("%s/%s", afl->in_dir, nl[i]->d_name);
- u8 *dfn = alloc_printf("%s/.state/deterministic_done/%s", afl->in_dir,
- nl[i]->d_name);
u8 passed_det = 0;
@@ -385,7 +392,6 @@ void read_testcases(afl_state_t *afl) {
if (!S_ISREG(st.st_mode) || !st.st_size || strstr(fn2, "/README.txt")) {
ck_free(fn2);
- ck_free(dfn);
continue;
}
@@ -401,7 +407,6 @@ void read_testcases(afl_state_t *afl) {
and probably very time-consuming. */
if (!access(dfn, F_OK)) passed_det = 1;
- ck_free(dfn);
add_to_queue(afl, fn2, st.st_size, passed_det);