Home | History | Annotate | Download | only in fuzz
      1 /* Copyright 2016 Google Inc. All Rights Reserved.
      2 
      3    Distributed under MIT license.
      4    See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
      5 */
      6 
      7 /* Simple runner for decode_fuzzer.cc */
      8 
      9 #include <stdio.h>
     10 #include <string.h>
     11 #include <stdlib.h>
     12 #include <stdint.h>
     13 
     14 extern "C" void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
     15 
     16 int main(int argc, char* *argv) {
     17   if (argc != 2) {
     18     fprintf(stderr, "Exactly one argument is expected.\n");
     19     exit(EXIT_FAILURE);
     20   }
     21 
     22   FILE* f = fopen(argv[1], "r");
     23   if (!f) {
     24     fprintf(stderr, "Failed to open input file.");
     25     exit(EXIT_FAILURE);
     26   }
     27 
     28   size_t max_len = 1 << 20;
     29   unsigned char* tmp = (unsigned char*)malloc(max_len);
     30   size_t len = fread(tmp, 1, max_len, f);
     31   if (ferror(f)) {
     32     fclose(f);
     33     fprintf(stderr, "Failed read input file.");
     34     exit(EXIT_FAILURE);
     35   }
     36   /* Make data after the end "inaccessible". */
     37   unsigned char* data = (unsigned char*)malloc(len);
     38   memcpy(data, tmp, len);
     39   free(tmp);
     40 
     41   LLVMFuzzerTestOneInput(data, len);
     42   free(data);
     43   exit(EXIT_SUCCESS);
     44 }
     45