Bug 203437 - scripts/kconfig/nconf.c stuck in infinite loop in search
Summary: scripts/kconfig/nconf.c stuck in infinite loop in search
Status: CLOSED CODE_FIX
Alias: None
Product: Tools
Classification: Unclassified
Component: Other (show other bugs)
Hardware: x86-64 Linux
: P1 normal
Assignee: Tools.Other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-26 15:04 UTC by GYt2bW
Modified: 2021-05-19 17:48 UTC (History)
3 users (show)

See Also:
Kernel Version: v5.1-rc6
Subsystem:
Regression: No
Bisected commit-id:


Attachments
naive workaround (703 bytes, patch)
2019-04-26 15:04 UTC, GYt2bW
Details | Diff

Description GYt2bW 2019-04-26 15:04:21 UTC
Created attachment 282549 [details]
naive workaround

Repro. steps:
1. $ make nconfig
2. Go to `File Systems`
3. Press `/` to search and type `cp`
4. Press and release DownArrow key, then UpArrow key
The `nconf` process is now stuck in an infinite loop using 100% CPU (one full core) 
5. press C-c to stop



This happens because `match_start` is `-1` and thus, since `index` will not reach values less than `0` (apparently), it won't ever exit the `while (true)` loop.

naive workaround(also attached):

```diff
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index ac92c0ded6c5..9f1d85acc572 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -505,7 +505,7 @@ static int get_mext_match(const char *match_str, match_f flag)
 
 	index = match_start;
 	index = (index + items_num) % items_num;
-	while (true) {
+	while (match_start != -1) {
 		char *str = k_menu_items[index].str;
 		if (strcasestr(str, match_str) != NULL)
 			return index;
@@ -516,8 +516,9 @@ static int get_mext_match(const char *match_str, match_f flag)
 			++index;
 		index = (index + items_num) % items_num;
 		if (index == match_start)
-			return -1;
+			break;
 	}
+	return -1;
 }
 
 /* Make a new item. */
```
Comment 1 Randy Dunlap 2019-09-26 03:13:42 UTC
Hi,
Please report this problem and your solution to
linux-kbuild@vger.kernel.org .  I would expect the kbuild/kconfig
maintainer to reply to it there.
Thanks.
Comment 2 GYt2bW 2019-09-27 16:33:16 UTC
(In reply to Randy Dunlap from comment #1)
yeah, I was afraid it wasn't that simple :)
now I'm being asked to do things from this: https://github.com/torvalds/linux/blob/master/Documentation/process/submitting-patches.rst

and let me just say it's never gonna happen.
Comment 3 GYt2bW 2019-09-27 16:36:21 UTC
besides, it is a `naive workaround`, I expect actual devs to fix it properly :D
Comment 4 Randy Dunlap 2019-09-27 16:40:49 UTC
The kbuild/kconfig maintainer is just asking for an email with the problem description and patch.  It's pretty easy to do that.  Although the patch would need a Signed-off-by: line with your real name and email address in it.

We mostly work through email, not bugzilla.  Anyway, thanks for the report and analysis.

Note You need to log in before you can comment on or make changes to this bug.