fuzzer-json.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 "fuzzer.h"
  18. #include "Zend/zend.h"
  19. #include "main/php_config.h"
  20. #include "main/php_main.h"
  21. #include <stdio.h>
  22. #include <stdint.h>
  23. #include <stdlib.h>
  24. #include "fuzzer-sapi.h"
  25. #include "ext/json/php_json_parser.h"
  26. int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  27. char *data = malloc(Size+1);
  28. memcpy(data, Data, Size);
  29. data[Size] = '\0';
  30. if (fuzzer_request_startup() == FAILURE) {
  31. return 0;
  32. }
  33. for (int option = 0; option <=1; ++option) {
  34. zval result;
  35. php_json_parser parser;
  36. php_json_parser_init(&parser, &result, data, Size, option, 10);
  37. if (php_json_yyparse(&parser) == SUCCESS) {
  38. zval_ptr_dtor(&result);
  39. }
  40. }
  41. php_request_shutdown(NULL);
  42. free(data);
  43. return 0;
  44. }
  45. int LLVMFuzzerInitialize(int *argc, char ***argv) {
  46. fuzzer_init_php();
  47. /* fuzzer_shutdown_php(); */
  48. return 0;
  49. }