fuzz_driver.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #include <cassert>
  15. #include <iostream>
  16. #include <fstream>
  17. #include <vector>
  18. extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
  19. int main(int argc, char **argv) {
  20. for (int i = 1; i < argc; i++) {
  21. std::ifstream in(argv[i], std::ios_base::in | std::ios_base::binary);
  22. in.seekg(0, in.end);
  23. size_t length = in.tellg();
  24. in.seekg (0, in.beg);
  25. std::cout << "Reading " << length << " bytes from " << argv[i] << std::endl;
  26. // Allocate exactly length bytes so that we reliably catch buffer overflows.
  27. std::vector<char> bytes(length);
  28. in.read(bytes.data(), bytes.size());
  29. assert(in);
  30. LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t *>(bytes.data()),
  31. bytes.size());
  32. std::cout << "Execution successful" << std::endl;
  33. }
  34. }