Skip to content

CLI: reject geozone index equal to MAX_GEOZONES_IN_CONFIG - #12263

Open
Wahaj18 wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
Wahaj18:fix-12225-geozone-index-bound
Open

Wahaj18 wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
Wahaj18:fix-12225-geozone-index-bound

Conversation

@Wahaj18

@Wahaj18 Wahaj18 commented Nov 28, 2026

Copy link
Copy Markdown

Fixes #12225

geozone <idx> ... checked idx > MAX_GEOZONES_IN_CONFIG, so index 63 got through even though the array has 63 zones (0-62). The command then wrote shape, type, altitudes and the rest one element past geoZonesConfig. The check is now >=, which matches the range the error message already prints and the check in geozone vertex.

Testing: I ran the SITL build and sent geozone 62 1 1 -100000 100000 0 2 4 and geozone 63 1 1 -100000 100000 0 2 4 over the CLI. Before the change both were accepted with no output. With it, 62 is still accepted and 63 prints geozone index must be between 0 and 62. The unit tests (make check, 635 tests) pass, though none of them cover cli.c.

The geozone command accepted index 63 although the last zone is 62, so the
following assignments wrote one element past the geoZonesConfig array.
@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

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

@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 geozone indices in the CLI

🐞 Bug fix 🕐 Less than 5 minutes

Grey Divider

AI Description

• Reject geozone index 63, which exceeds the configured 0–62 range.
• Prevent out-of-bounds writes to geozone configuration while preserving valid index 62.
Merge Risk 🟡 Medium

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 command validates and writes geozone configuration entries.
  • The configured array is bounded by MAX_GEOZONES_IN_CONFIG, and no separate affected end-to-end behavior was found in the inspected MSP or navigation consumers.
Sources

src/main/fc/cli.c[1784-1785]

        if (idx < 0 || idx >= MAX_GEOZONES_IN_CONFIG) {
            cliShowArgumentRangeError("geozone index", 0, MAX_GEOZONES_IN_CONFIG - 1);
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before, the check allowed idx == MAX_GEOZONES_IN_CONFIG; after, it rejects that value before the configuration writes.
  • The new correctness condition is a single inclusive upper-bound rule matching the declared array length; no new state interaction, transformation, ordering, or compatibility protocol is introduced.
Sources

src/main/fc/cli.c[1784-1785]

        if (idx < 0 || idx >= MAX_GEOZONES_IN_CONFIG) {
            cliShowArgumentRangeError("geozone index", 0, MAX_GEOZONES_IN_CONFIG - 1);

src/main/fc/cli.c[1874-1878]

        geoZonesConfigMutable(idx)->maxAltitude = maxAltitude;
        geoZonesConfigMutable(idx)->minAltitude = minAltitude;
        geoZonesConfigMutable(idx)->isSealevelRef = (bool)seaLevelRef;
        geoZonesConfigMutable(idx)->fenceAction = fenceAction;
        geoZonesConfigMutable(idx)->vertexCount = vertexCount;
Potential damage 🔴 High 🩹 Integrity

  • If the boundary behavior regresses, index 63 can pass validation and the subsequent field writes can address beyond the configured geozone array.
  • This can corrupt adjacent configuration or runtime state; the exact adjacent object is not established by the inspected source.
  • Reverting prevents further invalid writes, but any already-corrupted state may require resetting or manually restoring configuration.
Sources

src/main/fc/cli.c[1874-1878]

        geoZonesConfigMutable(idx)->maxAltitude = maxAltitude;
        geoZonesConfigMutable(idx)->minAltitude = minAltitude;
        geoZonesConfigMutable(idx)->isSealevelRef = (bool)seaLevelRef;
        geoZonesConfigMutable(idx)->fenceAction = fenceAction;
        geoZonesConfigMutable(idx)->vertexCount = vertexCount;

src/main/fc/cli.c[1784-1785]

        if (idx < 0 || idx >= MAX_GEOZONES_IN_CONFIG) {
            cliShowArgumentRangeError("geozone index", 0, MAX_GEOZONES_IN_CONFIG - 1);
Assessed commit 16b859f
Diagram

graph TD
  A["Geozone command"] --> B{"Index in range?"} -->|Yes| C["Zone configuration"]
  B -->|No| D["Range error"]
Loading
High-Level Assessment

Keep the boundary check at the CLI entry point. It matches the existing vertex-command check and rejects index 63 before any configuration writes; a broader validation redesign is unnecessary for this fix.

Files changed (1) +1 / -1

Bug fix (1) +1 / -1
cli.cExclude index 63 from geozone writes +1/-1

Exclude index 63 from geozone writes

• Changes the upper-bound check from '>' to '>= MAX_GEOZONES_IN_CONFIG'. This aligns accepted indices with the reported 0–62 range and prevents writes past 'geoZonesConfig'.

src/main/fc/cli.c

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.

CLI geozone accepts index 63 for a 63-element zone array

1 participant