Skip to content

Commit

Permalink
expand stack size implicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
addisoncrump committed Dec 30, 2023
1 parent ac8ea55 commit 5a8b5ab
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/pcre2_fuzzsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Written by Philip Hazel, October 2016
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

/* stack size adjustment */
#include <sys/time.h>
#include <sys/resource.h>

#define STACK_SIZE_MB 32

#ifndef PCRE2_CODE_UNIT_WIDTH
#define PCRE2_CODE_UNIT_WIDTH 8
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -496,6 +526,8 @@ int main(int argc, char **argv)
{
int i;

LLVMFuzzerInitialize(&argc, &argv);

if (argc < 2)
{
printf("** No arguments given\n");
Expand Down

0 comments on commit 5a8b5ab

Please sign in to comment.