Skip to content

Commit 9479af0

Browse files
de-nordicnvlsianpu
authored andcommitted
boot/bootutil: Fix probable uninitialized flash_area access
The commit fixes issue where failed flash_area_open in boot_write_status would result in flash_area_close call on uninitialized flash_area object. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 29fc848 commit 9479af0

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

boot/bootutil/src/loader.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
427427
const struct flash_area *fap;
428428
uint32_t off;
429429
int area_id;
430-
int rc;
430+
int rc = 0;
431431
uint8_t buf[BOOT_MAX_ALIGN];
432432
uint8_t align;
433433
uint8_t erased_val;
@@ -452,8 +452,7 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
452452

453453
rc = flash_area_open(area_id, &fap);
454454
if (rc != 0) {
455-
rc = BOOT_EFLASH;
456-
goto done;
455+
return BOOT_EFLASH;
457456
}
458457

459458
off = boot_status_off(fap) +
@@ -466,13 +465,10 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
466465
rc = flash_area_write(fap, off, buf, align);
467466
if (rc != 0) {
468467
rc = BOOT_EFLASH;
469-
goto done;
470468
}
471469

472-
rc = 0;
473-
474-
done:
475470
flash_area_close(fap);
471+
476472
return rc;
477473
}
478474
#endif /* !MCUBOOT_RAM_LOAD */

0 commit comments

Comments
 (0)