From 2a012a045c4d75bf9cb97ca1d4034a40afefe8c8 Mon Sep 17 00:00:00 2001 From: Sami Liedes Date: Sat, 19 Feb 2011 05:25:53 +0200 Subject: [PATCH] avr_loadcode(): If too much code, bail out instead of crashing. Check that the code to be loaded actually fits in the flash. Signed-off-by: Sami Liedes --- simavr/sim/sim_avr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/simavr/sim/sim_avr.c b/simavr/sim/sim_avr.c index 80c888b..d5611ba 100644 --- a/simavr/sim/sim_avr.c +++ b/simavr/sim/sim_avr.c @@ -150,6 +150,11 @@ void avr_set_console_register(avr_t * avr, avr_io_addr_t addr) void avr_loadcode(avr_t * avr, uint8_t * code, uint32_t size, uint32_t address) { + if (size > avr->flashend+1) { + fprintf(stderr, "avr_loadcode(): Attempted to load code of size %d but flash size is only %d.\n", + size, avr->flashend+1); + abort(); + } memcpy(avr->flash + address, code, size); } -- 2.39.5