common: readline: Fix always true test

The variable base is unsigned so >= 0 is always true. Fix this test
so that it is actually useful. The fix prevents the code from causing
a segfault in the case where Ctrl-w is pressed on a line consisting
only of spaces.

Fixes: dcc18ce0db ("cli: Implement delete-word in cread_line()")
Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
This commit is contained in:
Andrew Goodbody
2025-06-25 10:50:30 +01:00
committed by Tom Rini
parent 3833600dba
commit ebb2c9e550

View File

@@ -332,8 +332,8 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
if (cls->num) {
uint base, wlen;
for (base = cls->num - 1;
base >= 0 && buf[base] == ' ';)
for (base = cls->num;
base > 0 && buf[base - 1] == ' ';)
base--;
for (; base > 0 && buf[base - 1] != ' ';)
base--;