Skip to content

fix: companion text CLI refuses NaN tz, checks pin range, bounds board copy (13d-c) - #53

Merged
marcelverdult merged 6 commits into
integrationfrom
claude/13d-c-companion-cli-fixes-3ab9d0
Nov 10, 2026
Merged

marcelverdult merged 6 commits into
integrationfrom
claude/13d-c-companion-cli-fixes-3ab9d0

Conversation

@marcelverdult

Copy link
Copy Markdown
Owner

Step 13d-c of the refactoring series. After the harness (13d-a) and the tables (13d-b), this is the first step of the series that changes behaviour. It corrects three things in the companion's text CLI that the 13d-a tests had pinned as they were, each in its own commit and in one handler.

Behaviour changes

Command Before After
set tz.offset nan accepted and saved: NaN is false in both comparisons of tz < -12 || tz > 14 Error, must be from -12 to +14, nothing saved. Every other value answers as before.
set pin <n> atoi(), any number accepted and stored in the unsigned ble_pin only 0 or 100000 to 999999, the rule cmdSetDevicePin() of the app frame already has. Anything else answers Error, pin must be 0 or 6 digits, nothing saved. A five digit PIN, which worked before, is now refused. Text without a leading number still reads as 0 and is accepted, as with atoi().
board strcpy() of board.getManufacturerName() into the reply copy of at most 39 characters (StrHelper::strncpy with 40). The smallest reply buffer of the callers is 161 bytes (remote CLI). All 76 board names written as string literals in the tree are 37 characters or less (longest: Ikoka Handheld E22 30dBm (Xiao_nrf52)), so their reply is byte for byte the same.

What is in it

  • The three commits for the handlers, with the 13d-a tests that pinned the old behaviour rewritten: the NaN test now asserts the refusal, two set pin tests are rewritten and a third uses 100000 instead of 12, and two new board tests check a name at and above the limit with the guard bytes behind the reply buffer. MockBoard::manufacturer can be set for that and is reset in reset().
  • A "13d-c" section in docs/refactoring/0013-cli-command-table.md (each change as before and after, the limits that were tested, mutation table, size) and the README row for step 13.

Verification

  • All 27 native environments of run-unit-tests.yml: 2445 cases, 1 skipped, 2444 passed (13d-b: 2435; the 10 new cases are the two board tests in each of the five companion environments). The five companion environments have 125, 130, 146, 140 and 170 cases.
  • Mutations of each correction were run one at a time and each turned at least one test red (table in the note): the old conditions, limits moved by one, the old strcpy(), a limit that is too large or too small. Three of them were rerun on the final branch (tz upper bound 14 to 15, PIN upper bound 999999 to 9999999, board limit 40 to 20) and turned 1, 1 and 2 tests red.
  • RAK_4631_companion_radio_ble: flash 473976 before, 474088 after (+112 bytes), RAM unchanged at 149928.

Not verified

  • No board was flashed. The tests run on a 64 bit host.
  • What a saved NaN did on a board before this change, and how the BLE stack handles a PIN outside the range, was not measured.
  • Whether the companion apps send set pin with fewer than six digits was not checked.
  • Names of getManufacturerName() that are not string literals were read by hand in the session; the check of the literals was repeated on the final branch.
  • Size was measured on one build.

Left as it is

  • get wifi.pwd still answers the WiFi password in clear text, also to a contact with the remote CLI flag. Whether the apps use the command was not checked, so this stays an open point in the note.
  • The commands of the rescue console in checkCLIRescueCmd() have no tests and are not changed.

atof("nan") is NaN, so tz < -12 || tz > 14 was false and the value was
stored. The check now reads !(tz >= -12 && tz <= 14). Every value that was
valid or refused before behaves the same. The test that pinned NaN as
accepted now asserts the refusal, no save and an unchanged offset.
The pin must be 0 or 100000 to 999999, the rule of the app's
cmdSetDevicePin(). Anything else answers 'Error, pin must be 0 or 6
digits' and stores and saves nothing. The number is read into a long and
checked before it goes into the unsigned field, so negative and very large
numbers are refused. Text without a leading number still reads as 0 and is
accepted as pin 0, as with atoi(). The tests that pinned the missing check
now assert the range.
strcpy() of the manufacturer name into the reply buffer is now a copy of at
most 39 characters, like the 40 byte name in the app's device info frame.
The smallest caller buffer is 161 bytes. The longest board name in the
tree has 37 characters, so no real board answers differently. MockBoard
gets a settable name; new tests cover a name at the limit, a name over it
and the guard bytes behind the reply buffer.
@marcelverdult
marcelverdult merged commit 4d65cd2 into integration Nov 10, 2026
1 check passed
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.

1 participant