Skip to content

Commit 1363c7f

Browse files
committed
Fix buffer overflow issue
when in terminal fill mode
1 parent 7e26a15 commit 1363c7f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/term.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
373373
return -1;
374374
}
375375

376-
uint8_t * buf = malloc(mem->size + 0x10);
376+
// Allocate a buffer guaranteed to be large enough
377+
uint8_t * buf = calloc(mem->size + 0x10 + strlen(argv[argc - 2]), sizeof(uint8_t));
377378
if (buf == NULL) {
378379
avrdude_message(MSG_INFO, "%s (write): out of memory\n", progname);
379380
return -1;
@@ -535,6 +536,10 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
535536
buf[i - start_offset + ++data.bytes_grown] = data.a[7];
536537
}
537538
}
539+
540+
// Make sure buf does not overflow
541+
if (i - start_offset + data.bytes_grown > maxsize)
542+
break;
538543
}
539544

540545
// When in "fill" mode, the maximum size is already predefined

0 commit comments

Comments
 (0)