Skip to content

Commit 7fb5a93

Browse files
bwh-ctgregkh
authored andcommitted
kconfig/nconf: Fix hang when editing symbol with a long prompt
commit 79e51b5c2deea542b3bb8c66e0d502230b017dde upstream. Currently it is impossible to edit the value of a config symbol with a prompt longer than (terminal width - 2) characters. dialog_inputbox() calculates a negative x-offset for the input window and newwin() fails as this is invalid. It also doesn't check for this failure, so it busy-loops calling wgetch(NULL) which immediately returns -1. The additions in the offset calculations also don't match the intended size of the window. Limit the window size and calculate the offset similarly to show_scroll_win(). Fixes: 692d97c ("kconfig: new configuration interface (nconfig)") Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e321f38 commit 7fb5a93

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

scripts/kconfig/nconf.gui.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,14 @@ int dialog_inputbox(WINDOW *main_window,
364364
WINDOW *prompt_win;
365365
WINDOW *form_win;
366366
PANEL *panel;
367-
int i, x, y;
367+
int i, x, y, lines, columns, win_lines, win_cols;
368368
int res = -1;
369369
int cursor_position = strlen(init);
370370
int cursor_form_win;
371371
char *result = *resultp;
372372

373+
getmaxyx(stdscr, lines, columns);
374+
373375
if (strlen(init)+1 > *result_len) {
374376
*result_len = strlen(init)+1;
375377
*resultp = result = realloc(result, *result_len);
@@ -386,14 +388,19 @@ int dialog_inputbox(WINDOW *main_window,
386388
if (title)
387389
prompt_width = max(prompt_width, strlen(title));
388390

391+
win_lines = min(prompt_lines+6, lines-2);
392+
win_cols = min(prompt_width+7, columns-2);
393+
prompt_lines = max(win_lines-6, 0);
394+
prompt_width = max(win_cols-7, 0);
395+
389396
/* place dialog in middle of screen */
390-
y = (getmaxy(stdscr)-(prompt_lines+4))/2;
391-
x = (getmaxx(stdscr)-(prompt_width+4))/2;
397+
y = (lines-win_lines)/2;
398+
x = (columns-win_cols)/2;
392399

393400
strncpy(result, init, *result_len);
394401

395402
/* create the windows */
396-
win = newwin(prompt_lines+6, prompt_width+7, y, x);
403+
win = newwin(win_lines, win_cols, y, x);
397404
prompt_win = derwin(win, prompt_lines+1, prompt_width, 2, 2);
398405
form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2);
399406
keypad(form_win, TRUE);

0 commit comments

Comments
 (0)