Mercurial > minori
comparison dep/utf8proc/test/fuzz_main.c @ 343:1faa72660932
*: transfer back to cmake from autotools
autotools just made lots of things more complicated than
they should have and many things broke (i.e. translations)
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Thu, 20 Jun 2024 05:56:06 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 342:adb79bdde329 | 343:1faa72660932 |
|---|---|
| 1 #include <stdio.h> | |
| 2 #include <stdlib.h> | |
| 3 #include <stdint.h> | |
| 4 | |
| 5 /* Fuzz target entry point, works without libFuzzer */ | |
| 6 | |
| 7 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); | |
| 8 | |
| 9 int main(int argc, char **argv) | |
| 10 { | |
| 11 FILE *f; | |
| 12 char *buf = NULL; | |
| 13 long siz_buf; | |
| 14 | |
| 15 if(argc < 2) | |
| 16 { | |
| 17 fprintf(stderr, "no input file\n"); | |
| 18 goto err; | |
| 19 } | |
| 20 | |
| 21 f = fopen(argv[1], "rb"); | |
| 22 if(f == NULL) | |
| 23 { | |
| 24 fprintf(stderr, "error opening input file %s\n", argv[1]); | |
| 25 goto err; | |
| 26 } | |
| 27 | |
| 28 fseek(f, 0, SEEK_END); | |
| 29 | |
| 30 siz_buf = ftell(f); | |
| 31 rewind(f); | |
| 32 | |
| 33 if(siz_buf < 1) goto err; | |
| 34 | |
| 35 buf = (char*)malloc(siz_buf); | |
| 36 if(buf == NULL) | |
| 37 { | |
| 38 fprintf(stderr, "malloc() failed\n"); | |
| 39 goto err; | |
| 40 } | |
| 41 | |
| 42 if(fread(buf, siz_buf, 1, f) != 1) | |
| 43 { | |
| 44 fprintf(stderr, "fread() failed\n"); | |
| 45 goto err; | |
| 46 } | |
| 47 | |
| 48 (void)LLVMFuzzerTestOneInput((uint8_t*)buf, siz_buf); | |
| 49 | |
| 50 err: | |
| 51 free(buf); | |
| 52 | |
| 53 return 0; | |
| 54 } |
