Skip to content

Commit eddf74c

Browse files
dgarskedanielinux
authored andcommitted
Peer review fixes
1 parent d064a1b commit eddf74c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

hal/mpfs250.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,13 @@ static int qspi_wait_ready(uint32_t timeout_ms)
607607
uint8_t status;
608608
uint32_t count = 0;
609609
uint32_t max_count = timeout_ms * 1000; /* Rough timing */
610+
int ret;
610611

611612
do {
612-
qspi_transfer_block(QSPI_MODE_READ, &cmd, 1, &status, 1, 0);
613+
ret = qspi_transfer_block(QSPI_MODE_READ, &cmd, 1, &status, 1, 0);
614+
if (ret != 0) {
615+
return ret; /* Propagate transfer error */
616+
}
613617
if (!(status & 0x01)) { /* Bit 0 = WIP (Write In Progress) */
614618
return 0; /* Ready */
615619
}
@@ -788,9 +792,14 @@ int ext_flash_erase(uintptr_t address, int len)
788792
wolfBoot_printf("QSPI: Erase 0x%x, len %d\n", (uint32_t)address, len);
789793
#endif
790794

795+
/* Check for invalid length or integer overflow */
796+
if (len <= 0 || (uint32_t)len > UINT32_MAX - (uint32_t)address) {
797+
return -1;
798+
}
799+
791800
/* Align to sector boundaries */
792801
sector_addr = address & ~(FLASH_SECTOR_SIZE - 1);
793-
end_addr = address + len;
802+
end_addr = (uint32_t)address + (uint32_t)len;
794803

795804
/* Erase sectors */
796805
while (sector_addr < end_addr) {

src/elf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int elf_load_image_mmu(uint8_t *image, uint32_t image_sz, uintptr_t *pentry,
114114
if (ph_offset >= image_sz ||
115115
entry_size == 0 ||
116116
entry_count > (image_sz / entry_size) ||
117-
ph_offset + ((uint32_t)entry_count * entry_size) > image_sz) {
117+
((uint32_t)entry_count * entry_size) > (image_sz - ph_offset)) {
118118
return -3; /* program header table out of bounds */
119119
}
120120
entry_off = image + ph_offset;

0 commit comments

Comments
 (0)