Skip to content

Commit 8c94b43

Browse files
Ionicmasahir0y
authored andcommitted
kconfig: nconf: stop endless search loops
If the user selects the very first entry in a page and performs a search-up operation, or selects the very last entry in a page and performs a search-down operation that will not succeed (e.g., via [/]asdfzzz[Up Arrow]), nconf will never terminate searching the page. The reason is that in this case, the starting point will be set to -1 or n, which is then translated into (n - 1) (i.e., the last entry of the page) or 0 (i.e., the first entry of the page) and finally the search begins. This continues to work fine until the index reaches 0 or (n - 1), at which point it will be decremented to -1 or incremented to n, but not checked against the starting point right away. Instead, it's wrapped around to the bottom or top again, after which the starting point check occurs... and naturally fails. My original implementation added another check for -1 before wrapping the running index variable around, but Masahiro Yamada pointed out that the actual issue is that the comparison point (starting point) exceeds bounds (i.e., the [0,n-1] interval) in the first place and that, instead, the starting point should be fixed. This has the welcome side-effect of also fixing the case where the starting point was n while searching down, which also lead to an infinite loop. OTOH, this code is now essentially all his work. Amazingly, nobody seems to have been hit by this for 11 years - or at the very least nobody bothered to debug and fix this. Signed-off-by: Mihai Moldovan <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent a77a05d commit 8c94b43

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

scripts/kconfig/nconf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ static int get_mext_match(const char *match_str, match_f flag)
508508
else if (flag == FIND_NEXT_MATCH_UP)
509509
--match_start;
510510

511+
match_start = (match_start + items_num) % items_num;
511512
index = match_start;
512-
index = (index + items_num) % items_num;
513513
while (true) {
514514
char *str = k_menu_items[index].str;
515515
if (strcasestr(str, match_str) != NULL)

0 commit comments

Comments
 (0)