Skip to content

Commit 7c1f30d

Browse files
de-nordicnashif
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 <dominik.ermel@nordicsemi.no> (cherry picked from commit 8714c17)
1 parent f730851 commit 7c1f30d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/storage/stream_flash.h

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