Skip to content

Rework implementation of StorageOperation command - #3502

Merged
josesimoes merged 5 commits into
nanoframework:mainfrom
josesimoes:improve-storage-operation
Jul 27, 2026
Merged

Rework implementation of StorageOperation command#3502
josesimoes merged 5 commits into
nanoframework:mainfrom
josesimoes:improve-storage-operation

Conversation

@josesimoes

@josesimoes josesimoes commented Jul 24, 2026

Copy link
Copy Markdown
Member

Description

  • Now using storage file system to allow storing at any available storage.
  • Moved from platform to HAL level as this can now use a commom implementation.
  • Slight refactor to use file sytem API.
  • Update CMake accordingly.
  • Drop NameLength in Monitor_StorageOperation_Command.

⚠️ This requires Visual Studio extension v2022.14.1.13 v2019.14.1.13 nanoff >2.5.158 with support for this new command packet.

Motivation and Context

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

- Now using storage file system to allow storing at any available storage.
- Moved from platform to HAL level as this can now use a commom implementation.
- Slight refactor to use file sytem API.
- Update CMake accordingly.
- Drop NameLength in Monitor_StorageOperation_Command.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@josesimoes, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 10 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 704c7243-1a3d-4f36-ab3f-a16eb9da9266

📥 Commits

Reviewing files that changed from the base of the PR and between 6e4feb1 and 6f1d59d.

📒 Files selected for processing (1)
  • src/HAL/nanoHAL_StorageOperation.cpp
📝 Walkthrough

Walkthrough

Accessible-storage operations now use a shared nanoHAL implementation. The wire command and HAL signature omit NameLength, debugger invocation is updated, and common build definitions include the shared implementation while platform-specific storage source inclusion is removed.

Changes

Storage operation migration

Layer / File(s) Summary
Storage operation contract
src/CLR/Include/WireProtocol_MonitorCommands.h, src/HAL/Include/nanoHAL_StorageOperation.h, src/CLR/Debugger/Debugger.h
The monitor command removes NameLength; storage error codes and the revised HAL_StorageOperation declaration are centralized in the nanoHAL header.
Shared HAL execution and debugger call
src/HAL/nanoHAL_StorageOperation.cpp, src/CLR/Debugger/Debugger.cpp
The shared HAL parses storage paths and performs write, append, or delete operations; the debugger passes DataLength using the updated signature.
Shared HAL build wiring
CMake/*, targets/*/_common/CMakeLists.txt
Common builds include nanoHAL_StorageOperation.cpp, platform-specific storage source inclusion is removed, and ChibiOS adds conditional configuration-manager wiring.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: Type: enhancement, Area: Config-and-Build

Suggested reviewers: ellerbach

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, relevant, under 50 characters, and accurately summarizes the StorageOperation rework.
Description check ✅ Passed The description matches the changeset, covering storage file system use, HAL refactor, CMake updates, and NameLength removal.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/HAL/nanoHAL_StorageOperation.cpp`:
- Around line 18-20: Update HAL_StorageOperation to honor offset for Write and
other offset-based storage updates instead of discarding it; ensure writes begin
at the requested position while preserving Append’s EOF behavior. If offset
writes are unsupported, remove Offset consistently from the storage-operation
contract and tooling rather than ignoring it.
- Around line 143-146: Update HAL_StorageOperation so storageName is treated as
non-owned and is never freed when it aliases the command payload data. Remove
the platform_free(storageName) cleanup block, unless replacing it with an
explicit filename allocation/copy whose owned allocation alone is freed.
- Line 22: Remove the platform_free(storageName) cleanup from the storage
operation flow, where storageName references cmd->Data and SplitFilePath-derived
pointers. Keep payload-buffer ownership with the normal WireProtocol command
lifetime and do not free this borrowed pointer.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5534772c-8d27-4f5b-afda-1a78a9d9da17

📥 Commits

Reviewing files that changed from the base of the PR and between 5aaa438 and 5b2305e.

📒 Files selected for processing (17)
  • CMake/binutils.ESP32.cmake
  • CMake/binutils.common.cmake
  • src/CLR/Debugger/Debugger.cpp
  • src/CLR/Debugger/Debugger.h
  • src/CLR/Include/WireProtocol_MonitorCommands.h
  • src/HAL/Include/nanoHAL_StorageOperation.h
  • src/HAL/nanoHAL_StorageOperation.cpp
  • targets/ChibiOS/_common/CMakeLists.txt
  • targets/ChibiOS/_common/targetHAL_StorageOperation.cpp
  • targets/ChibiOS/_include/targetHAL_StorageOperation.h
  • targets/ESP32/_common/CMakeLists.txt
  • targets/ESP32/_common/targetHAL_StorageOperation.cpp
  • targets/ESP32/_include/targetHAL_StorageOperation.h
  • targets/FreeRTOS/NXP/_common/CMakeLists.txt
  • targets/ThreadX/Maxim/_common/CMakeLists.txt
  • targets/ThreadX/ST/_common/CMakeLists.txt
  • targets/ThreadX/SiliconLabs/_common/CMakeLists.txt
💤 Files with no reviewable changes (11)
  • targets/ChibiOS/_include/targetHAL_StorageOperation.h
  • targets/ESP32/_common/CMakeLists.txt
  • targets/ESP32/_common/targetHAL_StorageOperation.cpp
  • targets/ThreadX/Maxim/_common/CMakeLists.txt
  • targets/ESP32/_include/targetHAL_StorageOperation.h
  • src/CLR/Include/WireProtocol_MonitorCommands.h
  • targets/ThreadX/ST/_common/CMakeLists.txt
  • targets/ThreadX/SiliconLabs/_common/CMakeLists.txt
  • targets/ChibiOS/_common/targetHAL_StorageOperation.cpp
  • targets/ChibiOS/_common/CMakeLists.txt
  • targets/FreeRTOS/NXP/_common/CMakeLists.txt

Comment thread src/HAL/nanoHAL_StorageOperation.cpp Outdated
Comment thread src/HAL/nanoHAL_StorageOperation.cpp
Comment thread src/HAL/nanoHAL_StorageOperation.cpp Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/HAL/nanoHAL_StorageOperation.cpp (1)

49-126: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Sensitive Data Exposure (CWE-125): Out-of-bounds Read

Reachability: External

Bound Write/Append copies to the remaining command payload

HAL_StorageOperation computes fileData to start after storageName, then passes the wire DataLength directly to volume->Write; both paths also accept longer relativePath strings without bounding the pointer search. Reject commands where DataLength is larger than the bytes after the path terminator, and bound the offset before using fileData in Write.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/HAL/nanoHAL_StorageOperation.cpp` around lines 49 - 126, Validate the
command payload in HAL_StorageOperation before deriving fileData: ensure
relativePath is NUL-terminated within the available payload and reject any
DataLength exceeding the bytes remaining after that terminator. Bound the
computed offset and use the validated remaining length for volume->Write in both
StorageOperation_Write and StorageOperation_Append, preserving existing
WriteError handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/HAL/nanoHAL_StorageOperation.cpp`:
- Around line 88-93: Preserve the existing Offset wire contract and use it in
the storage write path: update the HAL storage-operation implementation around
HAL_StorageOperation and seek fileHandle to the requested offset before
volume->Write, propagating seek failure through the existing error handling.
Keep Debugger.cpp’s cmd->Offset flow and the HAL declaration consistent, and do
not discard offset.

---

Outside diff comments:
In `@src/HAL/nanoHAL_StorageOperation.cpp`:
- Around line 49-126: Validate the command payload in HAL_StorageOperation
before deriving fileData: ensure relativePath is NUL-terminated within the
available payload and reject any DataLength exceeding the bytes remaining after
that terminator. Bound the computed offset and use the validated remaining
length for volume->Write in both StorageOperation_Write and
StorageOperation_Append, preserving existing WriteError handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b03af3c1-df1f-4d19-a543-336f38c727bf

📥 Commits

Reviewing files that changed from the base of the PR and between 5b2305e and 6e4feb1.

📒 Files selected for processing (1)
  • src/HAL/nanoHAL_StorageOperation.cpp

Comment thread src/HAL/nanoHAL_StorageOperation.cpp

@Ellerbach Ellerbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works fine!

@josesimoes
josesimoes merged commit 69cc5bb into nanoframework:main Jul 27, 2026
41 checks passed
@josesimoes
josesimoes deleted the improve-storage-operation branch July 27, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants