summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2020-10-07 21:09:52 +0200
committerJakub Jelen <jjelen@redhat.com>2021-01-04 17:33:22 +0100
commit8676f404a2284a7638717e59da0d1921e3e688b8 (patch)
tree4fd2f605838daa383f1878a9136907d7e9742a92
parent98b626ec8cbe1d12b302a5e84f7b9eabeff0960a (diff)
Run fuzzers as part of CI at least with example inputs
This helps to catch errors earlier than in oss-fuzz and avoids 0% code coverages of fuzzers when generated by meson. Signed-off-by: Jakub Jelen <jjelen@redhat.com> Acked-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--fuzz/corpora/fuzz_options/test1
-rw-r--r--fuzz/corpora/fuzz_simpletlv/testbin0 -> 1022 bytes
-rw-r--r--fuzz/corpora/fuzz_xfer/testbin0 -> 443 bytes
l---------fuzz/db1
-rw-r--r--fuzz/fuzz_xfer.c23
-rw-r--r--fuzz/meson.build10
6 files changed, 18 insertions, 17 deletions
diff --git a/fuzz/corpora/fuzz_options/test b/fuzz/corpora/fuzz_options/test
new file mode 100644
index 0000000..281d52f
--- /dev/null
+++ b/fuzz/corpora/fuzz_options/test
@@ -0,0 +1 @@
+db="sql:hwdb" use_hw=removable
diff --git a/fuzz/corpora/fuzz_simpletlv/test b/fuzz/corpora/fuzz_simpletlv/test
new file mode 100644
index 0000000..de0b454
--- /dev/null
+++ b/fuzz/corpora/fuzz_simpletlv/test
Binary files differ
diff --git a/fuzz/corpora/fuzz_xfer/test b/fuzz/corpora/fuzz_xfer/test
new file mode 100644
index 0000000..8e7c9fb
--- /dev/null
+++ b/fuzz/corpora/fuzz_xfer/test
Binary files differ
diff --git a/fuzz/db b/fuzz/db
new file mode 120000
index 0000000..cc8cb4a
--- /dev/null
+++ b/fuzz/db
@@ -0,0 +1 @@
+../tests/db \ No newline at end of file
diff --git a/fuzz/fuzz_xfer.c b/fuzz/fuzz_xfer.c
index 2ee3ea2..09cee48 100644
--- a/fuzz/fuzz_xfer.c
+++ b/fuzz/fuzz_xfer.c
@@ -59,28 +59,17 @@ events_thread(gpointer arg)
return NULL;
}
-static void libcacard_init(char *argv0)
+static void libcacard_init(void)
{
VCardEmulOptions *command_line_options = NULL;
- gchar *path = NULL;
gchar *dbdir = NULL;
gchar *args = NULL;
VReader *r;
VCardEmulError ret;
- /* This is looking for NSS DB dir in the same directory, where the binary
- * is placed if path is absolute, or in the current directory otherwise */
- if (g_path_is_absolute(argv0)) {
- path = g_path_get_dirname(argv0);
- } else {
- gchar *wd = g_get_current_dir();
- gchar *abs = g_build_filename(wd, argv0, NULL);
- g_free(wd);
- path = g_path_get_dirname(abs);
- g_free(abs);
- }
- dbdir = g_build_filename(path, "db", NULL);
- g_free(path);
+ /* This will use the test directory when running as test and
+ * and dirname part of argv[0] when running from oss-fuzz */
+ dbdir = g_test_build_filename(G_TEST_DIST, "db", NULL);
args = g_strdup_printf(ARGS, dbdir);
thread = g_thread_new("fuzz/events", events_thread, NULL);
@@ -127,10 +116,12 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
(void) argc;
+ g_test_init(argc, argv, NULL);
+
loop = g_main_loop_new(NULL, TRUE);
g_debug("Initializing ...");
- libcacard_init(**argv);
+ libcacard_init();
reader = vreader_get_reader_by_id(0);
if (vreader_card_is_present(reader) != VREADER_OK) {
diff --git a/fuzz/meson.build b/fuzz/meson.build
index 67865fd..5d1307c 100644
--- a/fuzz/meson.build
+++ b/fuzz/meson.build
@@ -1,3 +1,7 @@
+env = environment()
+env.set('G_TEST_SRCDIR', meson.current_source_dir())
+env.set('G_TEST_BUILDDIR', meson.build_root())
+
fuzz_targets = [
'fuzz_xfer',
'fuzz_simpletlv',
@@ -17,9 +21,13 @@ else
endif
foreach target_name : fuzz_targets
- executable(target_name, [extra_sources, target_name + '.c'],
+ exe = executable(target_name, [extra_sources, target_name + '.c'],
objects: libcacard.extract_all_objects(),
c_args : extra_c_args,
dependencies : deps,
)
+ test(target_name, exe,
+ args: [meson.current_source_dir() + '/corpora/' + target_name + '/test'],
+ env: env,
+ )
endforeach