Skip to content

MSP: bounds-check layout and item in MSP2_INAV_OSD_SET_LAYOUT_ITEM - #12264

Open
Wahaj18 wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
Wahaj18:fix-12224-osd-layout-item-bounds
Open

Wahaj18 wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
Wahaj18:fix-12224-osd-layout-item-bounds

Conversation

@Wahaj18

@Wahaj18 Wahaj18 commented Nov 28, 2026

Copy link
Copy Markdown

Fixes #12224

MSP2_INAV_OSD_SET_LAYOUT_ITEM read layout and item from the payload and wrote straight to item_pos[layout][item] with no range check, so a bad request wrote outside osdLayoutsConfig. It now returns an error when layout >= OSD_LAYOUT_COUNT or item >= OSD_ITEM_COUNT, the same checks the MSP2_INAV_OSD_LAYOUTS getter does, before anything is written.

Testing: I ran the SITL build and sent the command over MSP v2 on TCP 5760. Before the change, layout 4 / item 0 and layout 0 / item 172 were ACKed, and layout 255 / item 255 crashed SITL with a segfault. With it, those three return an error and SITL keeps running, while layout 0 / item 0 and layout 3 / item 171 are still accepted. The unit tests (make check, 635 tests) pass, though none of them cover fc_msp.c.

The setter wrote item_pos[layout][item] without checking either index, so an
out-of-range request wrote outside osdLayoutsConfig. Reject it the same way the
MSP2_INAV_OSD_LAYOUTS getter does.
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Reject out-of-range OSD layout and item indices in MSP setter

🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Reject out-of-range layout and item indices before writing OSD item positions.
• Match the existing OSD layouts getter’s bounds checks, preventing malformed requests from writing
 outside the configuration.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed MSP command writes one indexed entry in the OSD layout-position table, and the OSD renderer consumes that table to position displayed elements.
  • These are producer and consumer hops of one bounded OSD layout behavior, not independent capabilities.
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before, the command only checked that each byte was present, then used both values as indexes into item_pos.
  • After, it adds independent upper-bound checks against OSD_LAYOUT_COUNT and OSD_ITEM_COUNT before the same write.
  • The new correctness condition is simply that each received index must be within its corresponding array dimension; existing safe reads still handle truncated payloads.
  • No new state interaction, transformation, ordering protocol, or cross-capability invariant is introduced.
Potential damage 🟢 Low 🩹 Reversible

  • If valid requests were incorrectly rejected or valid indexes were mishandled, a configured OSD element would not move or display as requested.
  • The effect is limited to OSD layout configuration and can be corrected by retrying or reapplying settings; no flight-control state is reached.
  • Out-of-range requests are intentionally rejected rather than becoming a supported downstream behavior.
  • Retrying the valid MSP request or restoring the layout configuration repairs the affected setting; reverting the code also restores the prior request behavior, with no external side effect requiring compensation.
Assessed commit 8c8dbd3
Diagram

graph TD
  R["MSP request"] --> L{"Layout valid?"} -->|Yes| I{"Item valid?"} -->|Yes| W["Write item position"]
  L -->|No| E["MSP error"]
  I -->|No| E
Loading
High-Level Assessment

Keep the checks at the setter boundary. They use the same limits as the getter and prevent an invalid index from reaching the write; a broader validation abstraction is not warranted for this two-condition fix.

Files changed (1) +2 / -2

Bug fix (1) +2 / -2
fc_msp.cValidate OSD indices before the layout-item write +2/-2

Validate OSD indices before the layout-item write

• The MSP2_INAV_OSD_SET_LAYOUT_ITEM handler now returns MSP_RESULT_ERROR when either the layout or item index exceeds its configured count. Valid indices continue through the existing position write and layout refresh path.

src/main/fc/fc_msp.c

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can turn these tips off under Display > Comment parts

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSP OSD layout setter writes outside item_pos when layout or item is out of range

1 participant