fuzz_main.c
This file
Path
tests/fuzz_main.c
54 lines · 970 bytes · C
Last changed by
Merge branch 'fuzzer_updates' of https://github.com/randy408/stb into workingSean Barrettbefore adoption3152efa
History of this fileTake it
1#include <stdint.h>2#include <stdio.h>3#include <stdlib.h>45/* fuzz target entry point, works without libFuzzer */67int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);89int main(int argc, char **argv)10{11 FILE *f;12 char *buf = NULL;13 long siz_buf;1415 if(argc < 2)16 {17 fprintf(stderr, "no input file\n");18 goto err;19 }2021 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 }2728 fseek(f, 0, SEEK_END);2930 siz_buf = ftell(f);31 rewind(f);3233 if(siz_buf < 1) goto err;3435 buf = (char*)malloc((size_t)siz_buf);36 if(buf == NULL)37 {38 fprintf(stderr, "malloc() failed\n");39 goto err;40 }4142 if(fread(buf, (size_t)siz_buf, 1, f) != 1)43 {44 fprintf(stderr, "fread() failed\n");45 goto err;46 }4748 (void)LLVMFuzzerTestOneInput((uint8_t*)buf, (size_t)siz_buf);4950err:51 free(buf);5253 return 0;54}