fuzzer: Add custom logger that explicitely raises abort()
authorEdward Hervey <edward@centricular.com>
Wed, 1 Nov 2017 08:45:36 +0000 (09:45 +0100)
committerEdward Hervey <bilboed@bilboed.com>
Wed, 1 Nov 2017 08:45:36 +0000 (09:45 +0100)
fuzzing/gst-discoverer.c
fuzzing/typefind.c

index 21ed67b..9138a1c 100644 (file)
@@ -68,6 +68,20 @@ appsrc_configuration (GstDiscoverer *dc, GstElement *source, gpointer data)
   gst_buffer_unref (buf);
 }
 
+static void
+custom_logger (const gchar   *log_domain,
+              GLogLevelFlags log_level,
+              const gchar   *message,
+              gpointer       unused_data)
+{
+  if (log_level & G_LOG_LEVEL_CRITICAL) {
+    g_printerr ("CRITICAL ERROR : %s\n", message);
+    g_abort();
+  } else if (log_level & G_LOG_LEVEL_WARNING) {
+    g_printerr ("WARNING : %s\n", message);
+  }
+}
+
 int LLVMFuzzerTestOneInput(const guint8 *data, size_t size)
 {
   GError *err = NULL;
@@ -79,6 +93,7 @@ int LLVMFuzzerTestOneInput(const guint8 *data, size_t size)
   if (!initialized) {
     /* We want critical warnings to assert so we can fix them */
     g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);
+    g_log_set_default_handler (custom_logger, NULL);
 
     /* Only initialize and register plugins once */
     gst_init (NULL, NULL);
index fd80148..3917f97 100644 (file)
@@ -41,6 +41,19 @@ GST_PLUGIN_STATIC_DECLARE (app);
  * The goal is to cover typefind code and implementation.
  *
  **/
+static void
+custom_logger (const gchar   *log_domain,
+              GLogLevelFlags log_level,
+              const gchar   *message,
+              gpointer       unused_data)
+{
+  if (log_level & G_LOG_LEVEL_CRITICAL) {
+    g_printerr ("CRITICAL ERROR : %s\n", message);
+    g_abort();
+  } else if (log_level & G_LOG_LEVEL_WARNING) {
+    g_printerr ("WARNING : %s\n", message);
+  }
+}
 
 int
 LLVMFuzzerTestOneInput (const guint8 * data, size_t size)
@@ -55,6 +68,7 @@ LLVMFuzzerTestOneInput (const guint8 * data, size_t size)
   if (!initialized) {
     /* We want critical warnings to assert so we can fix them */
     g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);
+    g_log_set_default_handler (custom_logger, NULL);
 
     /* Only initialize and register plugins once */
     gst_init (NULL, NULL);