From: "Yann E. MORIN" yann.morin.1998@free.fr
[ Upstream commit 694174f94ebeeb5ec5cc0e9de9b40c82057e1d95 ]
In case a menu has comment without letters/numbers (eg. characters matching the regexp '^[^[:alpha:][:digit:]]+$', for example - or *), hitting space will cycle through those comments, rather than selecting/deselecting the currently-highlighted option.
This is the behaviour of hitting any letter/digit: jump to the next option which prompt starts with that letter. The only letters that do not behave as such are 'y' 'm' and 'n'. Prompts that start with one of those three letters are instead matched on the first letter that is not 'y', 'm' or 'n'.
Fix that by treating 'space' as we treat y/m/n, ie. as an action key, not as shortcut to jump to prompt.
Signed-off-by: Yann E. MORIN yann.morin.1998@free.fr Signed-off-by: Peter Korsgaard peter@korsgaard.com Signed-off-by: Cherniaev Andrei dungeonlords789@naver.com [masahiro: took from Buildroot, adjusted the commit subject] Signed-off-by: Masahiro Yamada masahiroy@kernel.org Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
Now I have a complete understanding of the bug and fix. Let me provide my analysis:
**Backport Status: YES**
## Extensive Analysis:
This commit fixes a **clear user interface bug** in the kernel's menuconfig system (lxdialog) that affects the fundamental usability of kernel configuration. Here's the detailed analysis:
### The Bug: When a menu contains comment lines that start with non-alphanumeric characters (like `-`, `*`, or other special characters matching `^[^[:alpha:][:digit:]]+$`), pressing the space bar incorrectly cycles through these comment items instead of selecting/deselecting the currently highlighted option.
### Root Cause (from code analysis):
1. **Line 267 (original)**: The condition `if (strchr("ynmh", key))` checks if the pressed key is one of the special action keys (`y`, `n`, `m`, `h`). If it is, it sets `i = max_choice` to skip the jump- to-prompt logic.
2. **Lines 269-282**: For any other key (including space), the code searches for menu items starting with that character, treating it as a shortcut to jump to prompts beginning with that letter.
3. **The problem**: Space (ASCII 32) was not included in the special action keys list, so when pressed, it would trigger the jump-to- prompt logic. If menu items had comments starting with spaces or special characters, the space key would match these and jump to them instead of performing its intended action.
4. **Lines 362-398**: The switch statement shows that space (line 362) IS supposed to be an action key that returns value 8 (line 397-398), which indicates a selection/deselection action.
### The Fix: The fix is minimal and surgical - changing line 267 from: ```c if (strchr("ynmh", key)) ``` to: ```c if (strchr("ynmh ", key)) // Added space character ```
This ensures space is treated as an action key, not as a jump-to-prompt shortcut.
### Why This Should Be Backported:
1. **Fixes a real user-facing bug**: This directly impacts anyone using menuconfig to configure the kernel, which is a fundamental tool for kernel configuration.
2. **Minimal and contained fix**: The change is a single character addition with no architectural changes or new features.
3. **Low regression risk**: The fix only affects the specific broken behavior and restores the intended functionality that's already defined in the switch statement.
4. **Long-standing issue**: The commit message indicates this came from Buildroot, suggesting it's been affecting users across multiple projects for some time.
5. **Clear behavioral inconsistency**: The code clearly shows space was meant to be an action key (returning value 8 in the switch statement), but was incorrectly handled in the shortcut logic.
6. **No side effects**: The change only affects space key handling in menuconfig and doesn't touch any kernel runtime code or critical subsystems.
This is an ideal stable backport candidate - it fixes a clear bug with minimal change and risk.
scripts/kconfig/lxdialog/menubox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c index 6e6244df0c56..d4c19b7beebb 100644 --- a/scripts/kconfig/lxdialog/menubox.c +++ b/scripts/kconfig/lxdialog/menubox.c @@ -264,7 +264,7 @@ int dialog_menu(const char *title, const char *prompt, if (key < 256 && isalpha(key)) key = tolower(key);
- if (strchr("ynmh", key)) + if (strchr("ynmh ", key)) i = max_choice; else { for (i = choice + 1; i < max_choice; i++) {