summaryrefslogtreecommitdiffstats
path: root/misc/check_fuzzer.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
commit464df1d5e5ab1322e2dd0a7796939fff1aeefa9a (patch)
tree6a403684e0978f0287d7f0ec0e5aab1fd31a59e1 /misc/check_fuzzer.c
parentInitial commit. (diff)
downloade2fsprogs-464df1d5e5ab1322e2dd0a7796939fff1aeefa9a.tar.xz
e2fsprogs-464df1d5e5ab1322e2dd0a7796939fff1aeefa9a.zip
Adding upstream version 1.47.0.upstream/1.47.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc/check_fuzzer.c')
-rw-r--r--misc/check_fuzzer.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/misc/check_fuzzer.c b/misc/check_fuzzer.c
new file mode 100644
index 0000000..cee21bf
--- /dev/null
+++ b/misc/check_fuzzer.c
@@ -0,0 +1,61 @@
+/*
+ * Play with a file system image quickly to find UBSAN problems
+ *
+ * Run a file system through some of the libext2fs functions used by
+ * some fuzzer reports.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <ext2fs/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
+
+int main (int argc, char *argv[])
+{
+ errcode_t retval = 0;
+ ext2_filsys fs;
+ int exit_status = 1;
+
+ initialize_ext2_error_table();
+
+ if (argc != 2) {
+ fprintf(stderr, "%s: Usage <device|filesystem>\n", argv[0]);
+ exit(1);
+ }
+
+ retval = ext2fs_open(argv[1], 0, 0, 0,
+ unix_io_manager, &fs);
+ if (retval) {
+ com_err(argv[0], retval, "while trying to open '%s'",
+ argv[1]);
+ exit(1);
+ }
+
+ retval = ext2fs_read_inode_bitmap(fs);
+ if (retval) {
+ com_err(argv[0], retval, "while trying to read inode bitmaps");
+ goto errout;
+ }
+
+ retval = ext2fs_read_block_bitmap(fs);
+ if (retval) {
+ com_err(argv[0], retval, "while trying to read inode bitmaps");
+ goto errout;
+ }
+
+ retval = ext2fs_check_directory(fs, EXT2_ROOT_INO);
+ if (retval) {
+ com_err(argv[0], retval, "while trying to read inode bitmaps");
+ goto errout;
+ }
+ exit_status = 0;
+errout:
+ ext2fs_close(fs);
+ return exit_status;
+}