| 1 |
#include "blkidP.h" |
| 2 |
#include "fuzz.h" |
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
#include <unistd.h> |
| 6 |
|
| 7 |
static int process_file(const char *name) |
| 8 |
{ |
| 9 |
int rc = -1; |
| 10 |
blkid_probe pr = blkid_new_probe_from_filename(name); |
| 11 |
if (pr != NULL) { |
| 12 |
blkid_probe_enable_partitions(pr, TRUE); |
| 13 |
blkid_probe_set_partitions_flags(pr, FALSE); |
| 14 |
blkid_probe_enable_superblocks(pr, TRUE); |
| 15 |
blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_DEFAULT | BLKID_SUBLKS_FSINFO | BLKID_SUBLKS_MAGIC | BLKID_SUBLKS_VERSION | BLKID_SUBLKS_BADCSUM); |
| 16 |
rc = blkid_do_safeprobe(pr) == -1 ? -1 : 0; |
| 17 |
} |
| 18 |
blkid_free_probe(pr); |
| 19 |
return rc; |
| 20 |
} |
| 21 |
|
| 22 |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
| 23 |
{ |
| 24 |
int fd; |
| 25 |
char name[] = "/tmp/test-script-fuzz.XXXXXX"; |
| 26 |
|
| 27 |
fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC); |
| 28 |
if (fd == -1) |
| 29 |
err(EXIT_FAILURE, "mkostemp() failed"); |
| 30 |
|
| 31 |
if (write(fd, data, size) != (ssize_t)size) |
| 32 |
goto out; |
| 33 |
|
| 34 |
process_file(name); |
| 35 |
out: |
| 36 |
close(fd); |
| 37 |
unlink(name); |
| 38 |
return 0; |
| 39 |
} |
| 40 |
|
| 41 |
#ifndef FUZZ_TARGET |
| 42 |
int main(int argc, char **argv) |
| 43 |
{ |
| 44 |
for (int i = 1; i < argc; i++) { |
| 45 |
printf("%s ", argv[i]); |
| 46 |
if (process_file(argv[i]) == 0) |
| 47 |
printf(" OK\n"); |
| 48 |
else |
| 49 |
printf(" FAILED\n"); |
| 50 |
|
| 51 |
} |
| 52 |
} |
| 53 |
#endif |