xfs.c (933B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #include <err.h> 5 6 #include "fsfuzz.h" 7 8 int 9 xfs_init(struct fsfuzz_info *fs_info 10 __attribute__ ((unused))) 11 { 12 srand((unsigned int)time(NULL)); 13 return 0; 14 } 15 16 int 17 xfs_fuzz(struct fsfuzz_info *fs_info) 18 { 19 char *p; 20 size_t offset; 21 size_t i; 22 23 p = fs_info->img; 24 for (i = 0; i < 64 * 4; i++) { 25 /* The superblock in xfs is at offset 0 */ 26 offset = rand() % (65536 * 4); 27 if (offset + 3 >= fs_info->size) { 28 warnx("Wrong offset, ignoring"); 29 continue; 30 } 31 if (fs_info->verbosity) 32 printf("[+] Patching offset %#lx with 0xffffffff\n", 33 (long)offset); 34 p[offset + 0] = 0xff; 35 p[offset + 1] = 0xff; 36 p[offset + 2] = 0xff; 37 p[offset + 3] = 0xff; 38 } 39 return 0; 40 } 41 42 static struct fsfuzz_ops xfs_fuzz_ops = { 43 .name = "xfs", 44 .init = xfs_init, 45 .fuzz = xfs_fuzz 46 }; 47 48 __attribute__ ((constructor)) 49 static void 50 xfs_register(void) 51 { 52 fsfuzz_register(&xfs_fuzz_ops); 53 }