From: Mihai Moldovan <ionic@ionic.de>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH v3] kconfig: nconf: stop endless search loops
Date: Thu, 15 Apr 2021 09:28:03 +0200 [thread overview]
Message-ID: <20210415072803.16338-1-ionic@ionic.de> (raw)
In-Reply-To: <20210327120155.500-1-ionic@ionic.de>
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 <ionic@ionic.de>
---
v2: swap constant in comparison to right side, as requested by
Randy Dunlap <rdunlap@infradead.org>
v3: reimplement as suggested by Masahiro Yamada <masahiroy@kernel.org>,
which has the side-effect of also fixing endless looping in the
symmetric down-direction
scripts/kconfig/nconf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index e0f965529166..af814b39b876 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -504,8 +504,8 @@ static int get_mext_match(const char *match_str, match_f flag)
else if (flag == FIND_NEXT_MATCH_UP)
--match_start;
+ match_start = (match_start + items_num) % items_num;
index = match_start;
- index = (index + items_num) % items_num;
while (true) {
char *str = k_menu_items[index].str;
if (strcasestr(str, match_str) != NULL)
--
2.30.1
next prev parent reply other threads:[~2021-04-15 7:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-27 12:01 [PATCH] kconfig: nconf: stop endless search-up loops Mihai Moldovan
2021-03-27 15:58 ` Randy Dunlap
2021-03-27 22:12 ` Mihai Moldovan
2021-03-27 22:26 ` Randy Dunlap
2021-03-28 9:27 ` Mihai Moldovan
2021-03-28 10:37 ` Joe Perches
2021-03-28 10:32 ` Joe Perches
2021-03-28 16:16 ` Randy Dunlap
2021-03-28 9:52 ` [PATCH v2] " Mihai Moldovan
2021-04-10 5:47 ` Masahiro Yamada
2021-04-10 7:00 ` Mihai Moldovan
2021-04-10 9:12 ` Masahiro Yamada
2021-04-15 7:28 ` Mihai Moldovan [this message]
2021-04-16 5:40 ` [PATCH v3] kconfig: nconf: stop endless search loops Masahiro Yamada
2021-04-16 10:39 ` Mihai Moldovan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210415072803.16338-1-ionic@ionic.de \
--to=ionic@ionic.de \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox