fuzzer-parser.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Johannes Schlüter <johanes@php.net> |
  14. | Stanislav Malyshev <stas@php.net> |
  15. +----------------------------------------------------------------------+
  16. */
  17. #include <main/php.h>
  18. #include <main/php_main.h>
  19. #include <main/SAPI.h>
  20. #include <ext/standard/info.h>
  21. #include <ext/standard/php_var.h>
  22. #include <main/php_variables.h>
  23. #include "fuzzer.h"
  24. #include "fuzzer-sapi.h"
  25. int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  26. if (Size > 32 * 1024) {
  27. /* Large inputs have a large impact on fuzzer performance,
  28. * but are unlikely to be necessary to reach new codepaths. */
  29. return 0;
  30. }
  31. fuzzer_do_request_from_buffer("fuzzer.php", (const char *) Data, Size, /* execute */ 0);
  32. return 0;
  33. }
  34. int LLVMFuzzerInitialize(int *argc, char ***argv) {
  35. /* Compilation will often trigger fatal errors.
  36. * Use tracked allocation mode to avoid leaks in that case. */
  37. putenv("USE_TRACKED_ALLOC=1");
  38. fuzzer_init_php();
  39. /* fuzzer_shutdown_php(); */
  40. return 0;
  41. }