fuzzer-unserialize.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. +----------------------------------------------------------------------+
  15. */
  16. #include "fuzzer.h"
  17. #include "Zend/zend.h"
  18. #include "main/php_config.h"
  19. #include "main/php_main.h"
  20. #include <stdio.h>
  21. #include <stdint.h>
  22. #include <stdlib.h>
  23. #include "fuzzer-sapi.h"
  24. #include "ext/standard/php_var.h"
  25. int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  26. unsigned char *orig_data = malloc(Size+1);
  27. memcpy(orig_data, Data, Size);
  28. orig_data[Size] = '\0';
  29. if (fuzzer_request_startup() == FAILURE) {
  30. return 0;
  31. }
  32. fuzzer_setup_dummy_frame();
  33. {
  34. const unsigned char *data = orig_data;
  35. zval result;
  36. ZVAL_UNDEF(&result);
  37. php_unserialize_data_t var_hash;
  38. PHP_VAR_UNSERIALIZE_INIT(var_hash);
  39. php_var_unserialize(&result, (const unsigned char **) &data, data + Size, &var_hash);
  40. PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
  41. zval_ptr_dtor(&result);
  42. }
  43. free(orig_data);
  44. fuzzer_request_shutdown();
  45. return 0;
  46. }
  47. int LLVMFuzzerInitialize(int *argc, char ***argv) {
  48. fuzzer_init_php();
  49. /* fuzzer_shutdown_php(); */
  50. return 0;
  51. }