tests: cover CLI prefix stripping, set-pin gate, paged reply bounds, and ACL write failures

Changelog: -
This commit is contained in:
tth committed 2026-12-02 00:36:05 +01:00
1 parent 0dcc9c6e06
commit 5f31fc8e50
6 files changed
+192 -35

No files matched your search

+8 -18
View File
@@ -2126,14 +2126,7 @@ void MyMesh::enterCLIRescue() {
extern "C" void retainedClockInvalidate() __attribute__((weak)); // NRF52Board.cpp
bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) {
while (*command == ' ') command++; // skip leading spaces
if (strlen(command) > 4 && command[2] == '|') { // optional prefix (for companion radio CLI)
memcpy(reply, command, 3); // reflect the prefix back
reply += 3;
*reply = 0;
command += 3;
}
cli_args::stripPrefix(command, reply);
if (_prefs.getRadioPrefs()->handleCommand(command, sender_timestamp, reply)) { // is radio CLI command?
if (_prefs.getRadioPrefs()->isDirty()) { savePrefs(); }
@@ -2207,18 +2200,15 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
#endif
if (memcmp(command, "set pin ", 8) == 0) {
const char* err = nullptr;
#ifdef LOCKED_NODE
if (_cli_rescue) {
// CUSTOM (TeTeHacko): a known PIN = pair and read it all (checked after
// leading-space and XX| stripping so " set pin ..." cannot bypass it)
strcpy(reply, "Error: locked build");
return true;
}
const bool locked = true;
#else
const bool locked = false;
#endif
if (sender_timestamp == 0 && !_cli_rescue && (!_serial || !_serial->isConnectionSecure())) {
// CUSTOM (TeTeHacko): the same gate as CMD_SET_DEVICE_PIN -- through the
// CLI, USB set the PIN it may not set directly, then paired over BLE
strcpy(reply, "Error: set pin only over paired BLE");
if (!cli_args::canSetPin(sender_timestamp, _cli_rescue, locked,
_serial && _serial->isConnectionSecure(), &err)) {
strcpy(reply, err);
return true;
}
long pin; // atoi(): "abc" was PIN 0, i.e. a random one
+6 -12
View File
@@ -1,5 +1,6 @@
#include "MyMesh.h"
#include <algorithm>
#include <helpers/CliArgs.h>
#include <helpers/sensors/LPPDataHelpers.h>
#include <helpers/UTF8Helpers.h>
@@ -219,9 +220,7 @@ void MyMesh::formatNodesReply(char* reply, int max_len, uint16_t offset) {
prefix, (unsigned)n->type, (long)n->lat, (long)n->lon,
(int)n->snr, (int)n->rssi, (unsigned long)(now - n->heard_timestamp),
(unsigned long)n->pkt_hash, pathhex, n->name);
int ll = strlen(line);
if ((dp - reply) + ll + 24 > max_len) break; // room for trailer; never overflow reply
memcpy(dp, line, ll); dp += ll;
if (!cli_args::appendLine(dp, reply, max_len, 24, line)) break; // room for trailer; never overflow reply
}
dp += sprintf(dp, "E,%d,%d", i, total);
*dp = 0;
@@ -276,9 +275,7 @@ void MyMesh::formatRxLogReply(char* reply, int max_len, uint32_t cursor) {
(unsigned long)r->seq, (unsigned long)r->when,
(unsigned long)r->pkt_hash, (unsigned)r->header,
(int)r->snr, (int)r->rssi, pathhex);
int ll = strlen(line);
if ((dp - reply) + ll + 40 > max_len) break; // room for trailer; never overflow reply
memcpy(dp, line, ll); dp += ll;
if (!cli_args::appendLine(dp, reply, max_len, 40, line)) break; // room for trailer; never overflow reply
last = r->seq;
}
dp += sprintf(dp, "E,%lu,%lu,%lu", (unsigned long)last, (unsigned long)oldest, (unsigned long)newest);
@@ -1931,12 +1928,9 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
}
#endif
if (strlen(command) > 4 && command[2] == '|') { // optional prefix (for companion radio CLI)
memcpy(reply, command, 3); // reflect the prefix back
reply += 3;
reply_max = reply_max > 3 ? reply_max - 3 : 0;
command += 3;
}
const char* cmd = command;
cli_args::stripPrefix(cmd, reply, &reply_max);
command = const_cast<char*>(cmd);
// handle ACL related commands
if (memcmp(command, "setperm ", 8) == 0) { // format: setperm {pubkey-hex} {permissions-int8}