Skip to content

Commit a0065f8

Browse files
de-nordicnvlsianpu
authored andcommitted
bootutil: Fix boot_scramble_region escaping flash area
Incorrect range check fix. Signed-off-by: Dominik Ermel <[email protected]>
1 parent bb644c7 commit a0065f8

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

boot/bootutil/src/loader.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ boot_scramble_region(const struct flash_area *fa, uint32_t off, uint32_t size, b
12741274
end_offset = ALIGN_DOWN((off + size), write_block);
12751275
}
12761276

1277-
while (true) {
1277+
while (off != end_offset) {
12781278
/* Write over the area to scramble data that is there */
12791279
rc = flash_area_write(fa, off, buf, write_block);
12801280
if (rc != 0) {
@@ -1291,12 +1291,12 @@ boot_scramble_region(const struct flash_area *fa, uint32_t off, uint32_t size, b
12911291

12921292
off -= write_block;
12931293
} else {
1294-
if (end_offset < off) {
1294+
off += write_block;
1295+
1296+
if (end_offset <= off) {
12951297
/* Reached the end offset in range and already scrambled it */
12961298
break;
12971299
}
1298-
1299-
off += write_block;
13001300
}
13011301
}
13021302
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Fixed issue in boot_scramble_regions, where incorrect boundary
2+
check would cause function to attempt to write pass a designated
3+
flash area.

0 commit comments

Comments
 (0)