From 02761be7dfdbd88891abcdb6a15004960be70d0f Mon Sep 17 00:00:00 2001 From: Addison Crump Date: Mon, 20 Nov 2023 18:47:55 +0100 Subject: [PATCH] expand stack size implicitly --- src/pcre2_fuzzsupport.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/pcre2_fuzzsupport.c b/src/pcre2_fuzzsupport.c index e635eb3c2..a66770d25 100644 --- a/src/pcre2_fuzzsupport.c +++ b/src/pcre2_fuzzsupport.c @@ -13,6 +13,13 @@ Written by Philip Hazel, October 2016 #include #include #include +#include + +/* stack size adjustment */ +#include +#include + +#define STACK_SIZE_MB 32 #ifndef PCRE2_CODE_UNIT_WIDTH #define PCRE2_CODE_UNIT_WIDTH 8 @@ -213,8 +220,31 @@ return (*((uint32_t *)callout_data) > 100)? PCRE2_ERROR_CALLOUT : 0; /* Putting in this apparently unnecessary prototype prevents gcc from giving a "no previous prototype" warning when compiling at high warning level. */ +int LLVMFuzzerInitialize(int *, char ***); + int LLVMFuzzerTestOneInput(const unsigned char *, size_t); +int LLVMFuzzerInitialize(int *argc, char ***argv) +{ +int rc; +struct rlimit rlim; +getrlimit(RLIMIT_STACK, &rlim); +rlim.rlim_cur = STACK_SIZE_MB * 1024 * 1024; +if (rlim.rlim_cur > rlim.rlim_max) + { + fprintf(stderr, "hard stack size limit is too small (needed 8MiB)!\n"); + _exit(1); + } +rc = setrlimit(RLIMIT_STACK, &rlim); +if (rc != 0) + { + fprintf(stderr, "failed to expand stack size\n"); + _exit(1); + } + +return 0; +} + /* Here's the driving function. */ int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) @@ -496,6 +526,8 @@ int main(int argc, char **argv) { int i; +LLVMFuzzerInitialize(&argc, &argv); + if (argc < 2) { printf("** No arguments given\n");