aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-09-04 16:30:15 +0200
committerGitHub <noreply@github.com>2020-09-04 16:30:15 +0200
commitfc19aa96f78cd33ce7d548bad5c7e4d3efa069d1 (patch)
tree4ad1399aa4fed339a84b526b5a4a818ab8c9011a /src
parent6399f84ba2a15a4e41458509cd40a1d8658c8699 (diff)
parent50f61b64b1bbf2f5354bcff4f1d225965fee2d06 (diff)
downloadafl++-fc19aa96f78cd33ce7d548bad5c7e4d3efa069d1.tar.gz
Merge pull request #544 from ThomasTNO/export_env_vars
Export set afl_environment_variables to stats
Diffstat (limited to 'src')
-rw-r--r--src/afl-fuzz-stats.c62
-rw-r--r--src/afl-fuzz.c1
2 files changed, 53 insertions, 10 deletions
diff --git a/src/afl-fuzz-stats.c b/src/afl-fuzz-stats.c
index 0ce35cb7..b59a40e4 100644
--- a/src/afl-fuzz-stats.c
+++ b/src/afl-fuzz-stats.c
@@ -24,8 +24,57 @@
*/
#include "afl-fuzz.h"
+#include "envs.h"
#include <limits.h>
+/* Open file for writing */
+
+inline FILE *open_file(const char *fn) {
+
+ s32 fd;
+ FILE *f;
+
+ fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+
+ if (fd < 0) { PFATAL("Unable to create '%s'", fn); }
+
+ f = fdopen(fd, "w");
+
+ if (!f) { PFATAL("fdopen() failed"); }
+
+ return f;
+
+}
+
+/* Write fuzzer setup file */
+
+void write_fuzzer_config_file(afl_state_t *afl) {
+
+ u8 fn[PATH_MAX];
+ FILE *f;
+
+ snprintf(fn, PATH_MAX, "%s/fuzzer_config", afl->out_dir);
+ f = open_file(fn);
+
+ char *val;
+
+ uint32_t s_afl_env =
+ sizeof(afl_environment_variables) / sizeof(afl_environment_variables[0]) -
+ 1;
+ for (uint32_t i = 0; i < s_afl_env; i++) {
+
+ if ((val = getenv(afl_environment_variables[i])) != NULL) {
+
+ fprintf(f, "%s=%s\n", afl_environment_variables[i], val);
+
+ }
+
+ }
+
+ fclose(f);
+
+}
+
/* Update stats file for unattended monitoring. */
void write_stats_file(afl_state_t *afl, double bitmap_cvg, double stability,
@@ -36,20 +85,12 @@ void write_stats_file(afl_state_t *afl, double bitmap_cvg, double stability,
#endif
unsigned long long int cur_time = get_cur_time();
+ u32 t_bytes = count_non_255_bytes(afl, afl->virgin_bits);
u8 fn[PATH_MAX];
- s32 fd;
FILE * f;
- u32 t_bytes = count_non_255_bytes(afl, afl->virgin_bits);
snprintf(fn, PATH_MAX, "%s/fuzzer_stats", afl->out_dir);
-
- fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0600);
-
- if (fd < 0) { PFATAL("Unable to create '%s'", fn); }
-
- f = fdopen(fd, "w");
-
- if (!f) { PFATAL("fdopen() failed"); }
+ f = open_file(fn);
/* Keep last values in case we're called from another context
where exec/sec stats and such are not readily available. */
@@ -163,6 +204,7 @@ void write_stats_file(afl_state_t *afl, double bitmap_cvg, double stability,
? ""
: "default",
afl->orig_cmdline);
+
/* ignore errors */
if (afl->debug) {
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c
index 0df6c15c..e9ea8b62 100644
--- a/src/afl-fuzz.c
+++ b/src/afl-fuzz.c
@@ -1274,6 +1274,7 @@ int main(int argc, char **argv_orig, char **envp) {
seek_to = find_start_position(afl);
+ write_fuzzer_config_file(afl);
write_stats_file(afl, 0, 0, 0);
maybe_update_plot_file(afl, 0, 0);
save_auto(afl);