(root)/
glib-2.79.0/
fuzzing/
driver.c
       1  /*
       2   * Copyright 2018 LLVM contributors
       3   *
       4   * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
       5   *
       6   * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
       7   * See https://llvm.org/LICENSE.txt for license information.
       8   */
       9  
      10  /* Simpler gnu89 version of StandaloneFuzzTargetMain.c from LLVM */
      11  
      12  #include <assert.h>
      13  #include <stdio.h>
      14  #include <stdlib.h>
      15  
      16  extern int LLVMFuzzerTestOneInput (const unsigned char *data, size_t size);
      17  
      18  int
      19  main (int argc, char **argv)
      20  {
      21    FILE *f;
      22    long tell_result;
      23    size_t n_read, len;
      24    unsigned char *buf;
      25  
      26    if (argc < 2)
      27      return 1;
      28  
      29    f = fopen (argv[1], "r");
      30    assert (f);
      31    fseek (f, 0, SEEK_END);
      32    tell_result = ftell (f);
      33    assert (tell_result >= 0);
      34    len = (size_t) tell_result;
      35    fseek (f, 0, SEEK_SET);
      36    buf = (unsigned char*) malloc (len);
      37    n_read = fread (buf, 1, len, f);
      38    assert (n_read == len);
      39    LLVMFuzzerTestOneInput (buf, len);
      40  
      41    free (buf);
      42    fclose (f);
      43    printf ("Done!\n");
      44    return 0;
      45  }