mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 16:00:57 +00:00
core/sdcard: add out-of-bounds checks to emulator
This commit is contained in:
parent
5523c7bbef
commit
4ed6487a19
@ -34,6 +34,7 @@
|
||||
#endif
|
||||
|
||||
#define SDCARD_SIZE (64 * 1024 * 1024)
|
||||
#define SDCARD_BLOCKS (SDCARD_SIZE / SDCARD_BLOCK_SIZE)
|
||||
|
||||
static uint8_t *sdcard_buffer = NULL;
|
||||
static secbool sdcard_powered = secfalse;
|
||||
@ -103,6 +104,12 @@ secbool sdcard_read_blocks(uint32_t *dest, uint32_t block_num,
|
||||
if (sectrue != sdcard_powered) {
|
||||
return secfalse;
|
||||
}
|
||||
if (block_num >= SDCARD_BLOCKS) {
|
||||
return secfalse;
|
||||
}
|
||||
if (num_blocks > SDCARD_BLOCKS - block_num) {
|
||||
return secfalse;
|
||||
}
|
||||
memcpy(dest, sdcard_buffer + block_num * SDCARD_BLOCK_SIZE,
|
||||
num_blocks * SDCARD_BLOCK_SIZE);
|
||||
return sectrue;
|
||||
@ -113,6 +120,12 @@ secbool sdcard_write_blocks(const uint32_t *src, uint32_t block_num,
|
||||
if (sectrue != sdcard_powered) {
|
||||
return secfalse;
|
||||
}
|
||||
if (block_num >= SDCARD_BLOCKS) {
|
||||
return secfalse;
|
||||
}
|
||||
if (num_blocks > SDCARD_BLOCKS - block_num) {
|
||||
return secfalse;
|
||||
}
|
||||
memcpy(sdcard_buffer + block_num * SDCARD_BLOCK_SIZE, src,
|
||||
num_blocks * SDCARD_BLOCK_SIZE);
|
||||
return sectrue;
|
||||
|
Loading…
Reference in New Issue
Block a user