• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Play with a file system image quickly to find UBSAN problems
3  *
4  * Run a file system through some of the libext2fs functions used by
5  * some fuzzer reports.
6  */
7 
8 #include <stdio.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <time.h>
13 #include <sys/types.h>
14 #include <sys/time.h>
15 
16 #include <ext2fs/ext2_fs.h>
17 #include <ext2fs/ext2fs.h>
18 
main(int argc,char * argv[])19 int main (int argc, char *argv[])
20 {
21 	errcode_t	retval = 0;
22 	ext2_filsys	fs;
23 	int		exit_status = 1;
24 
25 	initialize_ext2_error_table();
26 
27 	if (argc != 2) {
28 		fprintf(stderr, "%s: Usage <device|filesystem>\n", argv[0]);
29 		exit(1);
30 	}
31 
32 	retval = ext2fs_open(argv[1], 0, 0, 0,
33 			     unix_io_manager, &fs);
34 	if (retval) {
35 		com_err(argv[0], retval, "while trying to open '%s'",
36 			argv[1]);
37 		exit(1);
38 	}
39 
40 	retval = ext2fs_read_inode_bitmap(fs);
41 	if (retval) {
42 		com_err(argv[0], retval, "while trying to read inode bitmaps");
43 		goto errout;
44 	}
45 
46 	retval = ext2fs_read_block_bitmap(fs);
47 	if (retval) {
48 		com_err(argv[0], retval, "while trying to read inode bitmaps");
49 		goto errout;
50 	}
51 
52 	retval = ext2fs_check_directory(fs, EXT2_ROOT_INO);
53 	if (retval) {
54 		com_err(argv[0], retval, "while trying to read inode bitmaps");
55 		goto errout;
56 	}
57 	exit_status = 0;
58 errout:
59 	ext2fs_close(fs);
60 	return exit_status;
61 }
62