From: Sami Liedes Date: Sat, 19 Feb 2011 03:25:53 +0000 (+0200) Subject: avr_loadcode(): If too much code, bail out instead of crashing. X-Git-Tag: v1.0a7~29 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=2a012a045c4d75bf9cb97ca1d4034a40afefe8c8;p=sx%2Fsimavr.git 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 --- 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); }