driver.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. * https://www.openssl.org/source/license.html
  8. * or in the file LICENSE in the source distribution.
  9. */
  10. #include <stdint.h>
  11. #include <unistd.h>
  12. #include <stdlib.h>
  13. #include <openssl/opensslconf.h>
  14. #include "fuzzer.h"
  15. #ifndef OPENSSL_NO_FUZZ_LIBFUZZER
  16. int LLVMFuzzerInitialize(int *argc, char ***argv);
  17. int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len);
  18. int LLVMFuzzerInitialize(int *argc, char ***argv)
  19. {
  20. return FuzzerInitialize(argc, argv);
  21. }
  22. int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
  23. {
  24. return FuzzerTestOneInput(buf, len);
  25. }
  26. #elif !defined(OPENSSL_NO_FUZZ_AFL)
  27. #define BUF_SIZE 65536
  28. int main(int argc, char** argv)
  29. {
  30. FuzzerInitialize(&argc, &argv);
  31. while (__AFL_LOOP(10000)) {
  32. uint8_t *buf = malloc(BUF_SIZE);
  33. size_t size = read(0, buf, BUF_SIZE);
  34. FuzzerTestOneInput(buf, size);
  35. free(buf);
  36. }
  37. FuzzerCleanup();
  38. return 0;
  39. }
  40. #else
  41. #error "Unsupported fuzzer"
  42. #endif