mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 20:10:18 +03:00
Add CLI validation of parameters and print a corrupted value message
Validates the index for lookup values to prevent referencing random memory. Also validates the range of numeric parameters. diff output will clearly show any corrupted parameters.
This commit is contained in:
parent
baaaaf9d8f
commit
a76d22bf60
1 changed files with 16 additions and 4 deletions
|
@ -384,6 +384,10 @@ static void cliPrintErrorLinef(const char *format, ...)
|
|||
cliPrintLinefeed();
|
||||
}
|
||||
|
||||
static void cliPrintCorruptMessage(int value)
|
||||
{
|
||||
cliPrintf("%d ###CORRUPTED CONFIG###", value);
|
||||
}
|
||||
|
||||
static void printValuePointer(const clivalue_t *var, const void *valuePointer, bool full)
|
||||
{
|
||||
|
@ -439,13 +443,21 @@ static void printValuePointer(const clivalue_t *var, const void *valuePointer, b
|
|||
|
||||
switch (var->type & VALUE_MODE_MASK) {
|
||||
case MODE_DIRECT:
|
||||
if ((value < var->config.minmax.min) || (value > var->config.minmax.max)) {
|
||||
cliPrintCorruptMessage(value);
|
||||
} else {
|
||||
cliPrintf("%d", value);
|
||||
if (full) {
|
||||
cliPrintf(" %d %d", var->config.minmax.min, var->config.minmax.max);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MODE_LOOKUP:
|
||||
if (value < lookupTables[var->config.lookup.tableIndex].valueCount) {
|
||||
cliPrint(lookupTables[var->config.lookup.tableIndex].values[value]);
|
||||
} else {
|
||||
cliPrintCorruptMessage(value);
|
||||
}
|
||||
break;
|
||||
case MODE_BITSET:
|
||||
if (value & 1 << var->config.bitpos) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue