fuzzer-mbstring.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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: Stanislav Malyshev <stas@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 "oniguruma.h"
  21. #include <stdio.h>
  22. #include <stdint.h>
  23. #include <stdlib.h>
  24. #include "fuzzer-sapi.h"
  25. int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  26. #ifdef HAVE_MBREGEX
  27. char *args[2];
  28. char *data = malloc(Size+1);
  29. memcpy(data, Data, Size);
  30. data[Size] = '\0';
  31. if (fuzzer_request_startup() == FAILURE) {
  32. return 0;
  33. }
  34. fuzzer_setup_dummy_frame();
  35. args[0] = data;
  36. args[1] = "test123";
  37. fuzzer_call_php_func("mb_ereg", 2, args);
  38. args[0] = data;
  39. args[1] = "test123";
  40. fuzzer_call_php_func("mb_eregi", 2, args);
  41. args[0] = data;
  42. args[1] = data;
  43. fuzzer_call_php_func("mb_ereg", 2, args);
  44. args[0] = data;
  45. args[1] = data;
  46. fuzzer_call_php_func("mb_eregi", 2, args);
  47. fuzzer_request_shutdown();
  48. free(data);
  49. #else
  50. fprintf(stderr, "\n\nERROR:\nPHP built without mbstring, recompile with --enable-mbstring to use this fuzzer\n");
  51. exit(1);
  52. #endif
  53. return 0;
  54. }
  55. int LLVMFuzzerInitialize(int *argc, char ***argv) {
  56. fuzzer_init_php();
  57. /* The default parse depth limit allows stack overflows under asan. */
  58. onig_set_parse_depth_limit(512);
  59. /* fuzzer_shutdown_php(); */
  60. return 0;
  61. }