Avoid length overflow when fetch starts beyond ROM

This commit is contained in:
Adam Gashlin 2022-01-23 18:14:10 -08:00 committed by Simon Eriksson
parent 0902da8113
commit d386930fa2

View file

@ -90,7 +90,9 @@ static int pi_dma_read(struct pi_controller *pi) {
static void pi_rom_fetch(struct pi_controller *pi, uint32_t source, int32_t length, uint8_t *dest) {
int l = length;
if (source + length > pi->rom_size)
if (source >= pi->rom_size)
l = 0;
else if (source + length > pi->rom_size)
l = pi->rom_size - source;
memcpy(dest, pi->rom + source, l);