mirror of
https://git.proxmox.com/git/fwupd
synced 2025-05-02 20:46:40 +00:00

Note that g_assert() should not be used in unit tests, since it is a no-op when compiling with G_DISABLE_ASSERT. Use g_assert() in production code, and g_assert_true() in unit tests. See https://github.com/fwupd/fwupd/issues/3790
33 lines
830 B
C
33 lines
830 B
C
/*
|
|
* Copyright (C) 2020 Richard Hughes <richard@hughsie.com>
|
|
*
|
|
* SPDX-License-Identifier: LGPL-2.1+
|
|
*/
|
|
|
|
#include <glib.h>
|
|
|
|
__attribute__((weak)) extern int
|
|
LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
|
|
__attribute__((weak)) extern int
|
|
LLVMFuzzerInitialize(int *argc, char ***argv);
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
g_assert_nonnull(LLVMFuzzerTestOneInput);
|
|
if (LLVMFuzzerInitialize != NULL)
|
|
LLVMFuzzerInitialize(&argc, &argv);
|
|
for (int i = 1; i < argc; i++) {
|
|
gsize bufsz = 0;
|
|
g_autofree gchar *buf = NULL;
|
|
g_autoptr(GError) error = NULL;
|
|
g_printerr("Running: %s\n", argv[i]);
|
|
if (!g_file_get_contents(argv[i], &buf, &bufsz, &error)) {
|
|
g_printerr("Failed to load: %s\n", error->message);
|
|
continue;
|
|
}
|
|
LLVMFuzzerTestOneInput((const guint8 *)buf, bufsz);
|
|
g_printerr("Done\n");
|
|
}
|
|
}
|