standalone_fuzz_target_runner.cc
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 2017, Max Dymond, <cmeister2@gmail.com>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 
23 #include <stdint.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 
27 #include "testinput.h"
28 
35 int main(int argc, char **argv)
36 {
37  int ii;
38  FILE *infile;
39  uint8_t *buffer = NULL;
40  size_t buffer_len;
41 
42  for(ii = 1; ii < argc; ii++) {
43  /* Try and open the file. */
44  infile = fopen(argv[ii], "rb");
45  if(infile) {
46  printf("[%s] Open succeeded! \n", argv[ii]);
47 
48  /* Get the length of the file. */
49  fseek(infile, 0L, SEEK_END);
50  buffer_len = ftell(infile);
51 
52  /* Reset the file indicator to the beginning of the file. */
53  fseek(infile, 0L, SEEK_SET);
54 
55  /* Allocate a buffer for the file contents. */
56  buffer = (uint8_t *)calloc(buffer_len, sizeof(uint8_t));
57  if(buffer) {
58  /* Read all the text from the file into the buffer. */
59  fread(buffer, sizeof(uint8_t), buffer_len, infile);
60  printf("[%s] Read %zu bytes, calling fuzzer\n", argv[ii], buffer_len);
61 
62  /* Call the fuzzer with the data. */
63  LLVMFuzzerTestOneInput(buffer, buffer_len);
64 
65  printf("[%s] Fuzzing complete\n", argv[ii]);
66 
67  /* Free the buffer as it's no longer needed. */
68  free(buffer);
69  buffer = NULL;
70  }
71  else
72  {
73  fprintf(stderr,
74  "[%s] Failed to allocate %zu bytes \n",
75  argv[ii],
76  buffer_len);
77  }
78 
79  /* Close the file as it's no longer needed. */
80  fclose(infile);
81  infile = NULL;
82  }
83  else
84  {
85  /* Failed to open the file. Maybe wrong name or wrong permissions? */
86  fprintf(stderr, "[%s] Open failed. \n", argv[ii]);
87  }
88  }
89 }
#define free(ptr)
Definition: curl_memory.h:130
char buffer[]
Definition: unit1308.c:48
#define printf
Definition: curl_printf.h:40
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Fuzzing entry point.
Definition: curl_fuzzer.cc:35
size_t fread(void *, size_t, size_t, FILE *)
int main(int argc, char **argv)
Main procedure for standalone fuzzing engine.
#define fprintf
Definition: curl_printf.h:41
#define calloc(nbelem, size)
Definition: curl_memory.h:126


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16