From bb4aadf968dfe7aa5a812de67b1fe041c50c9737 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Wed, 1 Nov 2017 09:45:36 +0100 Subject: [PATCH] fuzzer: Add custom logger that explicitely raises abort() --- fuzzing/gst-discoverer.c | 15 +++++++++++++++ fuzzing/typefind.c | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/fuzzing/gst-discoverer.c b/fuzzing/gst-discoverer.c index 21ed67b552..9138a1c17b 100644 --- a/fuzzing/gst-discoverer.c +++ b/fuzzing/gst-discoverer.c @@ -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); diff --git a/fuzzing/typefind.c b/fuzzing/typefind.c index fd80148c24..3917f97e94 100644 --- a/fuzzing/typefind.c +++ b/fuzzing/typefind.c @@ -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);