Skip to content

Commit 3de5b4d

Browse files
nvlsianpucarlescufi
authored andcommitted
[nrf noup] boot_record: fix potential infinite loop
Fixed potential infinite loop on access to a security counter which is unavailable for given image index. ref.: NSCIDB-1873 Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no> (cherry picked from commit b709feb)
1 parent 12dc7e3 commit 3de5b4d

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

boot/bootutil/src/boot_record.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,22 +354,17 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
354354
#endif
355355

356356
#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT) && defined(MCUBOOT_HW_ROLLBACK_PROT)
357-
image = 0;
358-
while (image < BOOT_IMAGE_NUMBER && !rc) {
357+
for (image = 0; image < BOOT_IMAGE_NUMBER && !rc; image++) {
359358
FIH_CALL(boot_nv_security_counter_get, fih_rc, image, &security_cnt);
360359
if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) {
361-
/* Some platforms support only a single security counter. */
360+
/* Some platforms expose only one NV counter; skip other image indices. */
362361
continue;
363362
}
364363

365364
rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO,
366365
BLINFO_SECURITY_COUNTER_IMAGE_0 + image,
367366
sizeof(security_cnt),
368367
(void *)&security_cnt);
369-
if (!rc) {
370-
break;
371-
}
372-
++image;
373368
}
374369
#endif /* !defined(MCUBOOT_SINGLE_APPLICATION_SLOT) && defined(MCUBOOT_HW_ROLLBACK_PROT) */
375370

0 commit comments

Comments
 (0)