fuzz_driver.cc
Go to the documentation of this file.
1 // Copyright 2017 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <cassert>
16 #include <iostream>
17 #include <fstream>
18 #include <vector>
19 
20 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
21 
22 int main(int argc, char **argv) {
23  for (int i = 1; i < argc; i++) {
24  std::ifstream in(argv[i], std::ios_base::in | std::ios_base::binary);
25  in.seekg(0, in.end);
26  size_t length = in.tellg();
27  in.seekg (0, in.beg);
28  std::cout << "Reading " << length << " bytes from " << argv[i] << std::endl;
29  // Allocate exactly length bytes so that we reliably catch buffer overflows.
30  std::vector<char> bytes(length);
31  in.read(bytes.data(), bytes.size());
32  assert(in);
33  LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t *>(bytes.data()),
34  bytes.size());
35  std::cout << "Execution successful" << std::endl;
36  }
37 }
main
int main(int argc, char **argv)
Definition: fuzz_driver.cc:22
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: sockaddr_utils_fuzzer_test.cc:29
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
bytes
uint8 bytes[10]
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:153
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:22