fix(core): make CLI autocomplete order-independent
What changed, and why it matters
This is a minor bug fix in the command-line interface (CLI) autocomplete feature used inside Trezor devices. When a user typed a partial command like 'reboot' and pressed Tab, the autocomplete behavior could differ depending on the internal order of the command list. In some builds (real hardware) it happened to work; in others (emulator) it could skip past a complete command name and suggest a longer one instead. The fix separates two meanings of the special '\0' character so autocomplete behaves consistently regardless of command order. There is no direct evidence this is a security vulnerability.
Treat as a normal reliability/usability fix. No urgent security action is indicated by the commit itself. If the CLI is reachable in production, consider whether inconsistent autocomplete could confuse users, but the commit does not suggest an exploit path.
Security signals we found
Behavior of a user-facing input feature depends on linker/constructor ordering
Fix removes a sentinel-value ambiguity that caused inconsistent autocomplete results
Evidence from the diff
In core/embed/rtl/cli.c, cli_autocomplete() used ‘\0’ both to mean ‘no match found yet’ and ‘the matched command ends exactly at the prefix’. Because ‘\0’ is also the C string terminator, a command whose name equals the prefix (e.g., ‘reboot’) would set next_char to ‘\0’. If that command was processed first, the loop would treat it as ‘no match yet’ and later overwrite next_char with a non-zero character from a longer command (e.g., ‘reboot-to-bootloader’), causing Tab to autocomplete past the exact match. The patch adds a separate boolean ‘found’ to track whether any match has been seen, making the two cases distinct and order-independent. The commit message notes the issue was visible in the emulator but hidden on hardware because GCC emitted the command section in reverse order there.
Changed components
core/embed/rtl/cli.cTrezor device CLI/autocompleteInspect captured patch +5 / −2
### core/embed/rtl/cli.c
@@ -399,15 +399,18 @@ static int cli_readch(cli_t* cli) {
}
// Finds the next character that can be used for autocomplete.
-// Returns '\0' if there are no more characters.
+// Returns '\0' if there are no more characters, including when a command
+// name ends at the prefix and a longer one continues it.
static char cli_autocomplete(cli_t* cli, const char* prefix) {
+ bool found = false;
char next_char = '\0';
size_t prefix_len = strlen(prefix);
for (size_t i = 0; i < cli->cmd_count; i++) {
const char* cmd = cli->cmd_array[i].name;
if (cstr_starts_with(cmd, prefix)) {
char ch = cmd[prefix_len];
- if (next_char == '\0') {
+ if (!found) {
+ found = true;
next_char = ch;
} else if (ch != next_char) {
return '\0';Why this scored 21/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.