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 8714c172edd1947a6348ac0f669d89668f5896c3)
diff --git a/include/storage/stream_flash.h b/include/storage/stream_flash.h
index 1a928fa..ecdb5a0 100644
--- a/include/storage/stream_flash.h
+++ b/include/storage/stream_flash.h
@@ -140,7 +140,8 @@
* @param settings_key key to use with the settings module for loading
* the stream write progress
*
- * @return non-negative on success, negative errno code on fail
+ * @return non-negative on success, -ERANGE in case when @p off is out
+ * of area designated for stream or negative errno code on fail
*/
int stream_flash_progress_load(struct stream_flash_ctx *ctx,
const char *settings_key);
diff --git a/subsys/storage/stream/stream_flash.c b/subsys/storage/stream/stream_flash.c
index bee7a5b..4eac23a 100644
--- a/subsys/storage/stream/stream_flash.c
+++ b/subsys/storage/stream/stream_flash.c
@@ -79,6 +79,11 @@
int rc;
struct flash_pages_info page;
+ if (off < ctx->offset || (off - ctx->offset) >= ctx->available) {
+ LOG_ERR("Offset out of designated range");
+ return -ERANGE;
+ }
+
rc = flash_get_page_info_by_offs(ctx->fdev, off, &page);
if (rc != 0) {
LOG_ERR("Error %d while getting page info", rc);