Skip to content
Snippets Groups Projects
Commit 86493994 authored by Gerlando Falauto's avatar Gerlando Falauto Committed by Mike Frysinger
Browse files

cmd_sf: add size checking to spi flash commands


SPI flash operations inadvertently stretching beyond the flash size will
result in a wraparound. This may be particularly dangerous when burning
u-boot, because the flash contents will be corrupted rendering the board
unusable, without any warning being issued.
So add a consistency checking so not to overflow past the flash size.

Signed-off-by: default avatarGerlando Falauto <gerlando.falauto@keymile.com>
Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
parent 41e17134
No related branches found
No related tags found
No related merge requests found
......@@ -211,6 +211,13 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
if (*argv[3] == 0 || *endp != 0)
return -1;
/* Consistency checking */
if (offset + len > flash->size) {
printf("ERROR: attempting %s past flash size (%#x)\n",
argv[0], flash->size);
return 1;
}
buf = map_physmem(addr, len, MAP_WRBACK);
if (!buf) {
puts("Failed to map physical memory\n");
......@@ -252,6 +259,13 @@ static int do_spi_flash_erase(int argc, char * const argv[])
if (ret != 1)
return -1;
/* Consistency checking */
if (offset + len > flash->size) {
printf("ERROR: attempting %s past flash size (%#x)\n",
argv[0], flash->size);
return 1;
}
ret = spi_flash_erase(flash, offset, len);
if (ret) {
printf("SPI flash %s failed\n", argv[0]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment