aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-05-15 09:27:15 +0200
committervan Hauser <vh@thc.org>2020-05-15 09:27:15 +0200
commitd536ddc24085bced267143b4f45102715d71693e (patch)
tree7028606718ed9e4bb0c8d11406ef9c6e4856ba94 /src
parent564399bd754e355d28da5b498856c05b63901661 (diff)
downloadafl++-d536ddc24085bced267143b4f45102715d71693e.tar.gz
change: slaves only sync from masters
Diffstat (limited to 'src')
-rw-r--r--src/afl-fuzz-init.c47
-rw-r--r--src/afl-fuzz-run.c18
-rw-r--r--src/afl-fuzz.c13
3 files changed, 57 insertions, 21 deletions
diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c
index 613d1437..518de8af 100644
--- a/src/afl-fuzz-init.c
+++ b/src/afl-fuzz-init.c
@@ -1315,6 +1315,36 @@ dir_cleanup_failed:
}
+/* If this is a -S slave, ensure a -M master is running */
+
+int check_master_exists(afl_state_t *afl) {
+
+ DIR * sd;
+ struct dirent *sd_ent;
+ u8 * fn;
+ sd = opendir(afl->sync_dir);
+ if (!sd) { PFATAL("Unable to open '%s'", afl->sync_dir); }
+ while ((sd_ent = readdir(sd))) {
+
+ /* Skip dot files and our own output directory. */
+
+ if (sd_ent->d_name[0] == '.' || !strcmp(afl->sync_id, sd_ent->d_name)) {
+
+ continue;
+
+ }
+
+ fn = alloc_printf("%s/%s/is_master", afl->sync_dir, sd_ent->d_name);
+ int res = access(fn, F_OK);
+ free(fn);
+ if (res == 0) return 1;
+
+ }
+
+ return 0;
+
+}
+
/* Prepare output directories and fds. */
void setup_dirs_fds(afl_state_t *afl) {
@@ -1330,18 +1360,15 @@ void setup_dirs_fds(afl_state_t *afl) {
}
- /*
- if (afl->is_master) {
+ if (afl->is_master) {
- u8 *x = alloc_printf("%s/%s/is_master", afl->sync_dir, afl->sync_id);
- int fd = open(x, O_CREAT | O_RDWR, 0644);
- if (fd < 0) FATAL("cannot create %s", x);
- free(x);
- close(fd);
-
- }
+ u8 *x = alloc_printf("%s/%s/is_master", afl->sync_dir, afl->sync_id);
+ int fd = open(x, O_CREAT | O_RDWR, 0644);
+ if (fd < 0) FATAL("cannot create %s", x);
+ free(x);
+ close(fd);
- */
+ }
if (mkdir(afl->out_dir, 0700)) {
diff --git a/src/afl-fuzz-run.c b/src/afl-fuzz-run.c
index bbcd9a99..3708cf1a 100644
--- a/src/afl-fuzz-run.c
+++ b/src/afl-fuzz-run.c
@@ -401,19 +401,15 @@ void sync_fuzzers(afl_state_t *afl) {
}
- /*
- // a slave only syncs from a master, a master syncs from everyone
- if (likely(afl->is_slave)) {
+ // a slave only syncs from a master, a master syncs from everyone
+ if (likely(afl->is_slave)) {
- u8 x = alloc_printf("%s/%s/is_master", afl->sync_dir, sd_ent->d_name);
- int res = access(x, F_OK);
- free(x);
- if (res != 0)
- continue;
+ u8 *x = alloc_printf("%s/%s/is_master", afl->sync_dir, sd_ent->d_name);
+ int res = access(x, F_OK);
+ free(x);
+ if (likely(res != 0)) continue;
- }
-
- */
+ }
/* Skip anything that doesn't have a queue/ subdirectory. */
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c
index 8625c37c..9240526e 100644
--- a/src/afl-fuzz.c
+++ b/src/afl-fuzz.c
@@ -1065,8 +1065,21 @@ int main(int argc, char **argv_orig, char **envp) {
init_count_class16();
+ if (afl->is_master && check_master_exists(afl) == 1) {
+
+ WARNF("It is wasteful to run more than one master!");
+
+ }
+
setup_dirs_fds(afl);
+ if (afl->is_slave && check_master_exists(afl) == 0) {
+
+ WARNF("no -M master found. You need to run one master!");
+ sleep(5);
+
+ }
+
setup_custom_mutators(afl);
setup_cmdline_file(afl, argv + optind);