Skip to content

Commit d304447

Browse files
committed
fuzzer: Set a maximum write length for the fuzzer
This prevents certain highly compressed payloads from timing out the fuzzer.
1 parent 42159f3 commit d304447

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

curl_fuzzer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
/* Temporary write array size */
7979
#define TEMP_WRITE_ARRAY_SIZE 10
8080

81+
/* Maximum write size in bytes to stop unbounded writes (50MB) */
82+
#define MAXIMUM_WRITE_LENGTH 52428800
83+
8184
/* Cookie-jar path. */
8285
#define FUZZ_COOKIE_JAR_PATH "/dev/null"
8386

@@ -180,6 +183,9 @@ typedef struct fuzz_data
180183
/* Temporary writefunction state */
181184
char write_array[TEMP_WRITE_ARRAY_SIZE];
182185

186+
/* Cumulative length of "written" data */
187+
size_t written_data;
188+
183189
/* Upload data and length; */
184190
const uint8_t *upload1_data;
185191
size_t upload1_data_len;

curl_fuzzer_callback.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,16 @@ size_t fuzz_write_callback(void *contents,
222222
exercised. */
223223
memcpy(fuzz->write_array, contents, copy_len);
224224

225+
/* Add on the total to the count. If it exceeds the maximum then return
226+
zero to the caller so that the transfer is terminated early. */
227+
fuzz->written_data += total;
228+
229+
if(fuzz->written_data > MAXIMUM_WRITE_LENGTH) {
230+
FV_PRINTF(fuzz,
231+
"FUZZ: Exceeded maximum write length (%lu) \n",
232+
fuzz->written_data);
233+
total = 0;
234+
}
235+
225236
return total;
226237
}

0 commit comments

Comments
 (0)