Skip to content

Commit

Permalink
Merge pull request #1245 from jluebbe/fuzzing
Browse files Browse the repository at this point in the history
prepare for oss-fuzz
  • Loading branch information
ejoerns committed Sep 4, 2023
2 parents 13067d3 + a4ff681 commit a5d984e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 6 deletions.
4 changes: 4 additions & 0 deletions fuzz/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
#include <context.h>
#include <bundle.h>

#include "fuzz.h"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
g_autofree gchar *tmpdir = NULL;
g_autofree gchar *bundlename = NULL;
g_autoptr(RaucBundle) bundle = NULL;
g_autoptr(GError) error = NULL;

fuzz_set_logging_func();

tmpdir = g_dir_make_tmp("rauc-XXXXXX", NULL);
g_assert_nonnull(tmpdir);

Expand Down
1 change: 1 addition & 0 deletions fuzz/bundle_fuzzer.corpus
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/*.raucb
46 changes: 46 additions & 0 deletions fuzz/fuzz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2018 pdknsk
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#include <gio/gio.h>
#include <glib.h>

int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);

#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
static GLogWriterOutput
empty_logging_func(GLogLevelFlags log_level, const GLogField *fields,
gsize n_fields, gpointer user_data)
{
return G_LOG_WRITER_HANDLED;
}
#endif

/* Disables logging for oss-fuzz. Must be used with each target. */
static void
fuzz_set_logging_func(void)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
static gboolean writer_set = FALSE;

if (!writer_set) {
g_log_set_writer_func(empty_logging_func, NULL, NULL);
writer_set = TRUE;
}
#endif
}
4 changes: 4 additions & 0 deletions fuzz/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
#include <context.h>
#include <manifest.h>

#include "fuzz.h"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
g_autoptr(GBytes) dt = g_bytes_new(data, size);
g_autoptr(RaucManifest) rm = NULL;
g_autoptr(GError) error = NULL;

fuzz_set_logging_func();

(void) load_manifest_mem(dt, &rm, &error);

return 0;
Expand Down
4 changes: 4 additions & 0 deletions fuzz/manifest_fuzzer.corpus
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test/broken-manifest.raucm
test/install-content/manifest.raucm
test/install-content/manifest.raucm.crypt
test/manifest.raucm
File renamed without changes.
12 changes: 6 additions & 6 deletions subprojects/glib.wrap
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[wrap-file]
directory = glib-2.76.4
source_url = https://download.gnome.org/sources/glib/2.76/glib-2.76.4.tar.xz
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/glib_2.76.4-1/glib-2.76.4.tar.xz
source_filename = glib-2.76.4.tar.xz
source_hash = 5a5a191c96836e166a7771f7ea6ca2b0069c603c7da3cba1cd38d1694a395dda
wrapdb_version = 2.76.4-1
directory = glib-2.76.5
source_url = https://download.gnome.org/sources/glib/2.76/glib-2.76.5.tar.xz
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/glib_2.76.5-1/glib-2.76.5.tar.xz
source_filename = glib-2.76.5.tar.xz
source_hash = ed3a9953a90b20da8e5578a79f7d1c8a532eacbe2adac82aa3881208db8a3abe
wrapdb_version = 2.76.5-1

[provide]
dependency_names = gthread-2.0, gobject-2.0, gmodule-no-export-2.0, gmodule-export-2.0, gmodule-2.0, glib-2.0, gio-2.0, gio-windows-2.0, gio-unix-2.0
Expand Down

0 comments on commit a5d984e

Please sign in to comment.