diff options
author | Philip Withnall <pwithnall@gnome.org> | 2023-12-04 17:36:00 +0000 |
---|---|---|
committer | Philip Withnall <pwithnall@gnome.org> | 2023-12-05 11:27:17 +0000 |
commit | 74a00cf508a24ba3b3bedeb4d4c05fd6d1211ead (patch) | |
tree | 7e894d6a588f820cc0390d3d2e54ac533d7f64b3 | |
parent | d9a91e56fe77329709410ee1eb2fdad6c147284e (diff) |
fuzzing: Add a basic fuzzing test using xdg_mime_dump()
We don’t particularly need to test `xdg_mime_dump()` itself, but it’s an
easy function to call to exercise a lot of the file loading, parsing,
and traversing code.
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
-rw-r--r-- | fuzzing/fuzz_dump.c | 28 | ||||
-rw-r--r-- | fuzzing/fuzz_dump.corpus | 1 | ||||
-rw-r--r-- | fuzzing/meson.build | 1 |
3 files changed, 30 insertions, 0 deletions
diff --git a/fuzzing/fuzz_dump.c b/fuzzing/fuzz_dump.c new file mode 100644 index 0000000..a5bd767 --- /dev/null +++ b/fuzzing/fuzz_dump.c @@ -0,0 +1,28 @@ +/* + * Copyright 2023 GNOME Foundation Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0 + */ + +#include <stddef.h> + +#include "setup.h" +#include "xdgmime.h" + +int +LLVMFuzzerTestOneInput (const unsigned char *data, + size_t size) +{ + int working_dir_fd; + + /* Silently return success on setup failure. Any non-success exit status + * counts as a fuzzing failure and indicates a bug. */ + if (!fuzz_setup (data, size, &working_dir_fd)) + return 0; + + xdg_mime_dump (); + + fuzz_teardown (working_dir_fd); + + return 0; +} diff --git a/fuzzing/fuzz_dump.corpus b/fuzzing/fuzz_dump.corpus new file mode 100644 index 0000000..d165ea8 --- /dev/null +++ b/fuzzing/fuzz_dump.corpus @@ -0,0 +1 @@ +corpuses/**
\ No newline at end of file diff --git a/fuzzing/meson.build b/fuzzing/meson.build index 7b29e6a..deffb8c 100644 --- a/fuzzing/meson.build +++ b/fuzzing/meson.build @@ -5,6 +5,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0 fuzz_targets = [ + 'fuzz_dump', ] deps = [libxdgmime_dep] |