Skip to content

Commit e0ad4a5

Browse files
committed
expand stack size implicitly
1 parent 44361c1 commit e0ad4a5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/pcre2_fuzzsupport.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ Written by Philip Hazel, October 2016
1313
#include <stdio.h>
1414
#include <stdlib.h>
1515
#include <string.h>
16+
#include <unistd.h>
17+
18+
/* stack size adjustment */
19+
#include <sys/time.h>
20+
#include <sys/resource.h>
21+
22+
#define STACK_SIZE_MB 32
1623

1724
#ifndef PCRE2_CODE_UNIT_WIDTH
1825
#define PCRE2_CODE_UNIT_WIDTH 8
@@ -213,8 +220,31 @@ return (*((uint32_t *)callout_data) > 100)? PCRE2_ERROR_CALLOUT : 0;
213220
/* Putting in this apparently unnecessary prototype prevents gcc from giving a
214221
"no previous prototype" warning when compiling at high warning level. */
215222

223+
int LLVMFuzzerInitialize(int *, char ***);
224+
216225
int LLVMFuzzerTestOneInput(const unsigned char *, size_t);
217226

227+
int LLVMFuzzerInitialize(int *argc, char ***argv)
228+
{
229+
int rc;
230+
struct rlimit rlim;
231+
getrlimit(RLIMIT_STACK, &rlim);
232+
rlim.rlim_cur = STACK_SIZE_MB * 1024 * 1024;
233+
if (rlim.rlim_cur > rlim.rlim_max)
234+
{
235+
fprintf(stderr, "hard stack size limit is too small (needed 8MiB)!\n");
236+
_exit(1);
237+
}
238+
rc = setrlimit(RLIMIT_STACK, &rlim);
239+
if (rc != 0)
240+
{
241+
fprintf(stderr, "failed to expand stack size\n");
242+
_exit(1);
243+
}
244+
245+
return 0;
246+
}
247+
218248
/* Here's the driving function. */
219249

220250
int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
@@ -496,6 +526,8 @@ int main(int argc, char **argv)
496526
{
497527
int i;
498528

529+
LLVMFuzzerInitialize(&argc, &argv);
530+
499531
if (argc < 2)
500532
{
501533
printf("** No arguments given\n");

0 commit comments

Comments
 (0)