Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport v3.6-branch] stream_flash: stream_flash_erase_page does not check whether requested offset is in range of stream flash owned area #80637

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/zephyr/storage/stream_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ int stream_flash_erase_page(struct stream_flash_ctx *ctx, off_t off);
* @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);
Expand Down
5 changes: 5 additions & 0 deletions subsys/storage/stream/stream_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ int stream_flash_erase_page(struct stream_flash_ctx *ctx, off_t off)
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);
Expand Down