@@ -13,6 +13,13 @@ Written by Philip Hazel, October 2016
13
13
#include <stdio.h>
14
14
#include <stdlib.h>
15
15
#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
16
23
17
24
#ifndef PCRE2_CODE_UNIT_WIDTH
18
25
#define PCRE2_CODE_UNIT_WIDTH 8
@@ -213,8 +220,31 @@ return (*((uint32_t *)callout_data) > 100)? PCRE2_ERROR_CALLOUT : 0;
213
220
/* Putting in this apparently unnecessary prototype prevents gcc from giving a
214
221
"no previous prototype" warning when compiling at high warning level. */
215
222
223
+ int LLVMFuzzerInitialize (int * , char * * * );
224
+
216
225
int LLVMFuzzerTestOneInput (const unsigned char * , size_t );
217
226
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
+
218
248
/* Here's the driving function. */
219
249
220
250
int LLVMFuzzerTestOneInput (const unsigned char * data , size_t size )
@@ -496,6 +526,8 @@ int main(int argc, char **argv)
496
526
{
497
527
int i ;
498
528
529
+ LLVMFuzzerInitialize (& argc , & argv );
530
+
499
531
if (argc < 2 )
500
532
{
501
533
printf ("** No arguments given\n" );
0 commit comments