Commit e768626d authored by Fabio Utzig's avatar Fabio Utzig
Browse files

Fixes trying to close an invalid flash map handle

This error was catched by Coverity and it happens when a fail occurs
opening a flash map handle, which is not checked by the close
routine.

Right now this only affects Zephyr, but extra checking was added
assuming that in a future Mynewt implementation close could actually
be changed to do something.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent e601417c
Loading
Loading
Loading
Loading
+4
Changes for boot/bootutil/src/loader.c: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -745,8 +745,12 @@ boot_copy_sector(int flash_area_id_src, int flash_area_id_dst,
    rc = 0;

done:
    if (fap_src) {
        flash_area_close(fap_src);
    }
    if (fap_dst) {
        flash_area_close(fap_dst);
    }
    return rc;
}

+7 −2
Changes for boot/zephyr/flash_map.c: 7 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -122,8 +122,13 @@ int flash_area_open(uint8_t id, const struct flash_area **area)
 */
void flash_area_close(const struct flash_area *area)
{
    struct flash_map_entry *entry = CONTAINER_OF(area, struct flash_map_entry,
                                                 area);
    struct flash_map_entry *entry;

    if (!area) {
        return;
    }

    entry = CONTAINER_OF(area, struct flash_map_entry, area);
    if (entry->magic != FLASH_MAP_ENTRY_MAGIC) {
        BOOT_LOG_ERR("invalid area %p (id %u)", area, area->fa_id);
        return;