upstream: https://github.com/mirage/ocaml-mbr
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update dune-project with external dependencies

+54 -6
+14 -6
fuzz/dune
··· 5 5 6 6 (executable 7 7 (name fuzz_mbr) 8 + (modules fuzz_mbr) 8 9 (libraries mbr crowbar)) 9 10 10 11 (rule 11 - (alias fuzz) 12 + (alias runtest) 12 13 (deps fuzz_mbr.exe) 13 14 (action 14 15 (run %{exe:fuzz_mbr.exe}))) 15 - 16 - ; AFL-instrumented build target 17 16 18 17 (rule 19 - (alias fuzz-afl) 18 + (alias fuzz) 19 + (enabled_if 20 + (= %{profile} afl)) 20 21 (deps 21 - (glob_files *.ml)) 22 + (source_tree corpus) 23 + fuzz_mbr.exe 24 + gen_corpus.exe) 22 25 (action 23 - (run echo "Build with: dune build --profile=afl fuzz/fuzz_mbr.exe"))) 26 + (echo "AFL fuzzer built: %{exe:fuzz_mbr.exe}\n"))) 27 + 28 + (executable 29 + (name gen_corpus) 30 + (modules gen_corpus) 31 + (libraries mbr unix))
+40
fuzz/gen_corpus.ml
··· 1 + (** Generate seed corpus for MBR fuzz testing. *) 2 + 3 + let () = 4 + (try Unix.mkdir "corpus" 0o755 5 + with Unix.Unix_error (Unix.EEXIST, _, _) -> ()); 6 + let write name data = 7 + let oc = open_out_bin (Filename.concat "corpus" name) in 8 + output_string oc data; 9 + close_out oc 10 + in 11 + (* Valid MBR with one partition *) 12 + let p1 = 13 + match 14 + Mbr.Partition.make ~active:false ~partition_type:0x83 2048l 1048576l 15 + with 16 + | Ok p -> p 17 + | Error _ -> failwith "failed to create partition" 18 + in 19 + let mbr = match Mbr.v [ p1 ] with Ok m -> m | Error _ -> failwith "mbr" in 20 + write "seed_000" (Mbr.to_string mbr); 21 + (* Active partition with FAT32 type *) 22 + let p2 = 23 + match Mbr.Partition.make ~active:true ~partition_type:0x0C 2048l 4096l with 24 + | Ok p -> p 25 + | Error _ -> failwith "failed to create partition" 26 + in 27 + let mbr2 = match Mbr.v [ p2 ] with Ok m -> m | Error _ -> failwith "mbr" in 28 + write "seed_001" (Mbr.to_string mbr2); 29 + (* Too short - exercises error paths *) 30 + write "seed_002" "\x00\x00\x00\x00"; 31 + (* All zeros, 512 bytes *) 32 + write "seed_003" (String.make 512 '\x00'); 33 + (* All ones, 512 bytes *) 34 + write "seed_004" (String.make 512 '\xFF'); 35 + (* Valid boot signature at end but garbage elsewhere *) 36 + let buf = Bytes.make 512 '\x00' in 37 + Bytes.set buf 510 '\x55'; 38 + Bytes.set buf 511 '\xAA'; 39 + write "seed_005" (Bytes.to_string buf); 40 + print_endline "gen_corpus: wrote 6 MBR seed files"