Skip to content

Commit de0fc02

Browse files
committed
Limit binutils fuzzing input size
Limit all the binutils fuzzing inputs to 16384 bytes, and fuzz_as to 1024 which is plenty large enough to wreak havok. This will fix at least some of the timeouts due to producing large amounts of output from large files.
1 parent ac0a67c commit de0fc02

File tree

13 files changed

+25
-2
lines changed

13 files changed

+25
-2
lines changed

projects/binutils/fuzz_addr2line.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
2121
int
2222
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
2323
{
24+
if (size > 16384)
25+
return 0;
2426
char filename[256];
2527
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
2628
FILE *fp = fopen(filename, "wb");

projects/binutils/fuzz_as.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ xatexit (void (*fn) (void) ATTRIBUTE_UNUSED)
3232

3333
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
3434
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
35+
if (size > 1024)
36+
return 0;
3537
char filename[256];
3638
sprintf(filename, "/tmp/libfuzzer-%d.s", getpid());
3739
FILE *fp = fopen(filename, "wb");

projects/binutils/fuzz_bfd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static int bufferToFile(char * name, const uint8_t *Data, size_t Size) {
3939
char *target = NULL;
4040

4141
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
42+
if (Size > 16384)
43+
return 0;
4244
char tmpfilename[32];
4345

4446
if (bfd_init() != BFD_INIT_MAGIC)

projects/binutils/fuzz_bfd_ext.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ static int bufferToFile(char *name, const uint8_t *Data, size_t Size) {
4242
}
4343

4444
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
45+
if (Size > 16384)
46+
return 0;
4547
char tmpfilename[32];
4648

4749
if (bfd_init() != BFD_INIT_MAGIC)

projects/binutils/fuzz_dlltool.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
6060
int
6161
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
6262
{
63-
if (size < 512) {
63+
if (size < 512 || size > 16384)
6464
return 0;
65-
}
6665

6766
/* def file */
6867
char filename[256];

projects/binutils/fuzz_dwarf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
2020
int
2121
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
2222
{
23+
if (size > 16384)
24+
return 0;
2325
char filename[256];
2426
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
2527
FILE *fp = fopen(filename, "wb");

projects/binutils/fuzz_nm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
2121
int
2222
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
2323
{
24+
if (size > 16384)
25+
return 0;
2426
char filename[256];
2527
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
2628
FILE *fp = fopen(filename, "wb");

projects/binutils/fuzz_objcopy.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ init_objcopy_global_state() {
9494
int
9595
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
9696
{
97+
if (size > 16384)
98+
return 0;
9799
char filename[256];
98100
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
99101
FILE *fp = fopen(filename, "wb");

projects/binutils/fuzz_objdump.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
3939
int
4040
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
4141
{
42+
if (size > 16384)
43+
return 0;
4244
char filename[256];
4345
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
4446
FILE *fp = fopen(filename, "wb");

projects/binutils/fuzz_ranlib_simulation.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
3131
int
3232
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
3333
{
34+
if (size > 16384)
35+
return 0;
3436
char filename[256];
3537
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
3638
FILE *fp = fopen(filename, "wb");

0 commit comments

Comments
 (0)