about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--include/afl-fuzz.h13
-rw-r--r--include/config.h3
-rw-r--r--include/envs.h1
-rw-r--r--src/afl-fuzz-state.c7
-rw-r--r--src/afl-fuzz-statsd.c140
-rw-r--r--src/afl-fuzz.c5
6 files changed, 127 insertions, 42 deletions
diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h
index 92375b2c..ffb518ad 100644
--- a/include/afl-fuzz.h
+++ b/include/afl-fuzz.h
@@ -359,7 +359,8 @@ typedef struct afl_env_vars {
 
   u8 *afl_tmpdir, *afl_custom_mutator_library, *afl_python_module, *afl_path,
       *afl_hang_tmout, *afl_forksrv_init_tmout, *afl_skip_crashes, *afl_preload,
-      *afl_max_det_extras, *afl_statsd_host, *afl_statsd_port;
+      *afl_max_det_extras, *afl_statsd_host, *afl_statsd_port,
+      *afl_statsd_tags_flavor;
 
 } afl_env_vars_t;
 
@@ -638,6 +639,9 @@ typedef struct afl_state {
   u64                statsd_last_send_ms;
   struct sockaddr_in statsd_server;
   int                statsd_sock;
+  char *             statsd_tags_flavor;
+  char *             statsd_tags_format;
+  char *             statsd_metric_format;
 
   double stats_avg_exec;
 
@@ -961,9 +965,10 @@ void show_init_stats(afl_state_t *);
 
 /* StatsD */
 
-int statsd_socket_init(afl_state_t *afl);
-int statsd_send_metric(afl_state_t *afl);
-int statsd_format_metric(afl_state_t *afl, char *buff, size_t bufflen);
+void statsd_setup_format(afl_state_t *afl);
+int  statsd_socket_init(afl_state_t *afl);
+int  statsd_send_metric(afl_state_t *afl);
+int  statsd_format_metric(afl_state_t *afl, char *buff, size_t bufflen);
 
 /* Run */
 
diff --git a/include/config.h b/include/config.h
index c0a04565..3d6b0395 100644
--- a/include/config.h
+++ b/include/config.h
@@ -50,9 +50,6 @@ Server config can be adjusted with AFL_STATSD_HOST and AFL_STATSD_PORT env var.
 #define STATSD_DEFAULT_PORT 8125
 #define STATSD_DEFAULT_HOST "127.0.0.1"
 
-/* comment out to disable tags. */
-#define USE_DOGSTATSD_TAGS
-
 /* If you want to have the original afl internal memory corruption checks.
    Disabled by default for speed. it is better to use "make ASAN_BUILD=1". */
 
diff --git a/include/envs.h b/include/envs.h
index 1fc9e83d..16da14cb 100644
--- a/include/envs.h
+++ b/include/envs.h
@@ -137,6 +137,7 @@ static char *afl_environment_variables[] = {
     "AFL_SKIP_CRASHES",
     "AFL_STATSD_HOST",
     "AFL_STATSD_PORT",
+    "AFL_STATSD_TAGS_FLAVOR",
     "AFL_TMIN_EXACT",
     "AFL_TMPDIR",
     "AFL_TOKEN_FILE",
diff --git a/src/afl-fuzz-state.c b/src/afl-fuzz-state.c
index 5e719a85..77b30b5b 100644
--- a/src/afl-fuzz-state.c
+++ b/src/afl-fuzz-state.c
@@ -377,6 +377,13 @@ void read_afl_environment(afl_state_t *afl, char **envp) {
             afl->afl_env.afl_statsd_port =
                 (u8 *)get_afl_env(afl_environment_variables[i]);
 
+          } else if (!strncmp(env, "AFL_STATSD_TAGS_FLAVOR",
+
+                              afl_environment_variable_len)) {
+
+            afl->afl_env.afl_statsd_tags_flavor =
+                (u8 *)get_afl_env(afl_environment_variables[i]);
+
           }
 
         } else {
diff --git a/src/afl-fuzz-statsd.c b/src/afl-fuzz-statsd.c
index 9cb8fde4..f77df17e 100644
--- a/src/afl-fuzz-statsd.c
+++ b/src/afl-fuzz-statsd.c
@@ -12,6 +12,107 @@
 #define MAX_TAG_LEN 200
 #define METRIC_PREFIX "fuzzing"
 
+/* Tags format for metrics
+  DogStatsD:
+  metric.name:<value>|<type>|#key:value,key2:value2
+
+  InfluxDB
+  metric.name,key=value,key2=value2:<value>|<type>
+
+  Librato
+  metric.name#key=value,key2=value2:<value>|<type>
+
+  SignalFX
+  metric.name[key=value,key2=value2]:<value>|<type>
+
+*/
+
+// after the whole metric.
+#define DOGSTATSD_TAGS_FORMAT "|#banner:%s,afl_version:%s"
+
+// just after the metric name.
+#define LIBRATO_TAGS_FORMAT "#banner=%s,afl_version=%s"
+#define INFLUXDB_TAGS_FORMAT ",banner=%s,afl_version=%s"
+#define SIGNALFX_TAGS_FORMAT "[banner=%s,afl_version=%s]"
+
+// For DogstatsD
+#define STATSD_TAGS_AFTER_METRICS                                            \
+  METRIC_PREFIX                                                              \
+      ".cycle_done:%llu|g%s\n" METRIC_PREFIX                                 \
+      ".cycles_wo_finds:%llu|g%s\n" METRIC_PREFIX                            \
+      ".execs_done:%llu|g%s\n" METRIC_PREFIX                                 \
+      ".execs_per_sec:%0.02f|g%s\n" METRIC_PREFIX                            \
+      ".paths_total:%u|g%s\n" METRIC_PREFIX                                  \
+      ".paths_favored:%u|g%s\n" METRIC_PREFIX                                \
+      ".paths_found:%u|g%s\n" METRIC_PREFIX                                  \
+      ".paths_imported:%u|g%s\n" METRIC_PREFIX                               \
+      ".max_depth:%u|g%s\n" METRIC_PREFIX ".cur_path:%u|g%s\n" METRIC_PREFIX \
+      ".pending_favs:%u|g%s\n" METRIC_PREFIX                                 \
+      ".pending_total:%u|g%s\n" METRIC_PREFIX                                \
+      ".variable_paths:%u|g%s\n" METRIC_PREFIX                               \
+      ".unique_crashes:%llu|g%s\n" METRIC_PREFIX                             \
+      ".unique_hangs:%llu|g%s\n" METRIC_PREFIX                               \
+      ".total_crashes:%llu|g%s\n" METRIC_PREFIX                              \
+      ".slowest_exec_ms:%u|g%s\n" METRIC_PREFIX                              \
+      ".edges_found:%u|g%s\n" METRIC_PREFIX                                  \
+      ".var_byte_count:%u|g%s\n" METRIC_PREFIX ".havoc_expansion:%u|g%s\n"
+
+// For Librato, InfluxDB, SignalFX
+#define STATSD_TAGS_MID_METRICS                                              \
+  METRIC_PREFIX                                                              \
+      ".cycle_done%s:%llu|g\n" METRIC_PREFIX                                 \
+      ".cycles_wo_finds%s:%llu|g\n" METRIC_PREFIX                            \
+      ".execs_done%s:%llu|g\n" METRIC_PREFIX                                 \
+      ".execs_per_sec%s:%0.02f|g\n" METRIC_PREFIX                            \
+      ".paths_total%s:%u|g\n" METRIC_PREFIX                                  \
+      ".paths_favored%s:%u|g\n" METRIC_PREFIX                                \
+      ".paths_found%s:%u|g\n" METRIC_PREFIX                                  \
+      ".paths_imported%s:%u|g\n" METRIC_PREFIX                               \
+      ".max_depth%s:%u|g\n" METRIC_PREFIX ".cur_path%s:%u|g\n" METRIC_PREFIX \
+      ".pending_favs%s:%u|g\n" METRIC_PREFIX                                 \
+      ".pending_total%s:%u|g\n" METRIC_PREFIX                                \
+      ".variable_paths%s:%u|g\n" METRIC_PREFIX                               \
+      ".unique_crashes%s:%llu|g\n" METRIC_PREFIX                             \
+      ".unique_hangs%s:%llu|g\n" METRIC_PREFIX                               \
+      ".total_crashes%s:%llu|g\n" METRIC_PREFIX                              \
+      ".slowest_exec_ms%s:%u|g\n" METRIC_PREFIX                              \
+      ".edges_found%s:%u|g\n" METRIC_PREFIX                                  \
+      ".var_byte_count%s:%u|g\n" METRIC_PREFIX ".havoc_expansion%s:%u|g\n"
+
+void statsd_setup_format(afl_state_t *afl) {
+
+  if (strcmp(afl->afl_env.afl_statsd_tags_flavor, "dogstatsd") == 0) {
+
+    afl->statsd_tags_format = DOGSTATSD_TAGS_FORMAT;
+    afl->statsd_metric_format = STATSD_TAGS_AFTER_METRICS;
+
+  } else if (strcmp(afl->afl_env.afl_statsd_tags_flavor, "librato") == 0) {
+
+    afl->statsd_tags_format = LIBRATO_TAGS_FORMAT;
+    afl->statsd_metric_format = STATSD_TAGS_MID_METRICS;
+
+  } else if (strcmp(afl->afl_env.afl_statsd_tags_flavor, "influxdb") == 0) {
+
+    afl->statsd_tags_format = INFLUXDB_TAGS_FORMAT;
+    afl->statsd_metric_format = STATSD_TAGS_MID_METRICS;
+
+  } else if (strcmp(afl->afl_env.afl_statsd_tags_flavor, "signalfx") == 0) {
+
+    afl->statsd_tags_format = SIGNALFX_TAGS_FORMAT;
+    afl->statsd_metric_format = STATSD_TAGS_MID_METRICS;
+
+  } else {
+
+    // No tags at all.
+    afl->statsd_tags_format = "";
+    // Still need to pick a format. Doesn't change anything since if will be
+    // replaced by the empty string anyway.
+    afl->statsd_metric_format = STATSD_TAGS_MID_METRICS;
+
+  }
+
+}
+
 int statsd_socket_init(afl_state_t *afl) {
 
   /* Default port and host.
@@ -87,7 +188,7 @@ int statsd_send_metric(afl_state_t *afl) {
              (struct sockaddr *)&afl->statsd_server,
              sizeof(afl->statsd_server)) == -1) {
 
-    if (!close(afl->statsd_sock)) { perror("Cannot close socket"); }
+    if (!close(afl->statsd_sock)) { FATAL("Cannot close socket"); }
     afl->statsd_sock = 0;
     WARNF("Cannot sendto");
     return -1;
@@ -100,45 +201,14 @@ int statsd_send_metric(afl_state_t *afl) {
 
 int statsd_format_metric(afl_state_t *afl, char *buff, size_t bufflen) {
 
-/* Metric format:
-<some.namespaced.name>:<value>|<type>
-*/
-#ifdef USE_DOGSTATSD_TAGS
-  /* Tags format: DogStatsD
-  <some.namespaced.name>:<value>|<type>|#key:value,key:value,key
-  */
   char tags[MAX_TAG_LEN * 2] = {0};
-  snprintf(tags, MAX_TAG_LEN * 2, "|#banner:%s,afl_version:%s", afl->use_banner,
+  snprintf(tags, MAX_TAG_LEN * 2, afl->statsd_tags_format, afl->use_banner,
            VERSION);
-#else
-  /* No tags.
-   */
-  char *tags = "";
-#endif
+
   /* Sends multiple metrics with one UDP Packet.
   bufflen will limit to the max safe size.
   */
-  snprintf(buff, bufflen,
-           METRIC_PREFIX ".cycle_done:%llu|g%s\n" METRIC_PREFIX
-                         ".cycles_wo_finds:%llu|g%s\n" METRIC_PREFIX
-                         ".execs_done:%llu|g%s\n" METRIC_PREFIX
-                         ".execs_per_sec:%0.02f|g%s\n" METRIC_PREFIX
-                         ".paths_total:%u|g%s\n" METRIC_PREFIX
-                         ".paths_favored:%u|g%s\n" METRIC_PREFIX
-                         ".paths_found:%u|g%s\n" METRIC_PREFIX
-                         ".paths_imported:%u|g%s\n" METRIC_PREFIX
-                         ".max_depth:%u|g%s\n" METRIC_PREFIX
-                         ".cur_path:%u|g%s\n" METRIC_PREFIX
-                         ".pending_favs:%u|g%s\n" METRIC_PREFIX
-                         ".pending_total:%u|g%s\n" METRIC_PREFIX
-                         ".variable_paths:%u|g%s\n" METRIC_PREFIX
-                         ".unique_crashes:%llu|g%s\n" METRIC_PREFIX
-                         ".unique_hangs:%llu|g%s\n" METRIC_PREFIX
-                         ".total_crashes:%llu|g%s\n" METRIC_PREFIX
-                         ".slowest_exec_ms:%u|g%s\n" METRIC_PREFIX
-                         ".edges_found:%u|g%s\n" METRIC_PREFIX
-                         ".var_byte_count:%u|g%s\n" METRIC_PREFIX
-                         ".havoc_expansion:%u|g%s\n",
+  snprintf(buff, bufflen, afl->statsd_metric_format,
            afl->queue_cycle ? (afl->queue_cycle - 1) : 0, tags,
            afl->cycles_wo_finds, tags, afl->fsrv.total_execs, tags,
            afl->fsrv.total_execs /
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c
index 0b08f426..e0e9487f 100644
--- a/src/afl-fuzz.c
+++ b/src/afl-fuzz.c
@@ -891,6 +891,11 @@ int main(int argc, char **argv_orig, char **envp) {
 
   }
 
+  #ifdef USE_STATSD
+  statsd_setup_format(afl);
+  statsd_socket_init(afl);
+  #endif
+
   if (strchr(argv[optind], '/') == NULL && !afl->unicorn_mode) {
 
     WARNF(cLRD