Skip to content

Commit 230174e

Browse files
committed
nvm_select_fresh_sector: fix flag offset
The offset for the sector flags position to compare the two redundant blocks with NVM_FLASH_WRITEONCE mode was wrong, resulting in a negative offset, which in turn caused an out-of-bound access outside of the UPDATE partition space.
1 parent dd4bd8e commit 230174e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libwolfboot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ static int RAMFUNCTION nvm_select_fresh_sector(int part)
308308
break;
309309
}
310310
/* Examine previous position one byte ahead */
311-
byte_0 = get_base_offset(base, (1 - off));
312-
byte_1 = get_base_offset(base, (1 - (WOLFBOOT_SECTOR_SIZE + off)));
311+
byte_0 = get_base_offset(base, (off - 1));
312+
byte_1 = get_base_offset(base, ((WOLFBOOT_SECTOR_SIZE + off) - 1));
313313

314314
sel = FLAG_CMP(byte_0, byte_1);
315315
break;

0 commit comments

Comments
 (0)