From f20cc4b7a47755f470b39f26b63269fa366f620f Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Mon, 24 May 2021 14:10:37 +0000 Subject: [PATCH] storage/flash_map: Fix flash area bounds checking The commit adds check if offset is positive; previously negative offset would be allowed, which means that writing flash before flash area start was possible. Signed-off-by: Dominik Ermel --- subsys/storage/flash_map/flash_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/storage/flash_map/flash_map.c b/subsys/storage/flash_map/flash_map.c index 313877f7ed5..6024c23dab9 100644 --- a/subsys/storage/flash_map/flash_map.c +++ b/subsys/storage/flash_map/flash_map.c @@ -80,7 +80,7 @@ void flash_area_close(const struct flash_area *fa) static inline bool is_in_flash_area_bounds(const struct flash_area *fa, off_t off, size_t len) { - return (off <= fa->fa_size && off + len <= fa->fa_size); + return (off >= 0) && ((off + len) <= fa->fa_size); } #if defined(CONFIG_FLASH_PAGE_LAYOUT)