Skip to content

Commit 03bc6e0

Browse files
de-nordichenrikbrixandersen
authored andcommitted
storage/stream_flash: Fix range check in stream_flash_erase_page
Added check where stream_flash_erase_page checks if requested offset is actually within stream flash designated area. Fixes #79800 Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 8714c17)
1 parent 6aeb7a2 commit 03bc6e0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/zephyr/storage/stream_flash.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ int stream_flash_erase_page(struct stream_flash_ctx *ctx, off_t off);
141141
* @param settings_key key to use with the settings module for loading
142142
* the stream write progress
143143
*
144-
* @return non-negative on success, negative errno code on fail
144+
* @return non-negative on success, -ERANGE in case when @p off is out
145+
* of area designated for stream or negative errno code on fail
145146
*/
146147
int stream_flash_progress_load(struct stream_flash_ctx *ctx,
147148
const char *settings_key);

subsys/storage/stream/stream_flash.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ int stream_flash_erase_page(struct stream_flash_ctx *ctx, off_t off)
7979
int rc;
8080
struct flash_pages_info page;
8181

82+
if (off < ctx->offset || (off - ctx->offset) >= ctx->available) {
83+
LOG_ERR("Offset out of designated range");
84+
return -ERANGE;
85+
}
86+
8287
rc = flash_get_page_info_by_offs(ctx->fdev, off, &page);
8388
if (rc != 0) {
8489
LOG_ERR("Error %d while getting page info", rc);

0 commit comments

Comments
 (0)