From c3797d40a1c57352192c6106cc0f435e7d9c11e8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 7 Nov 2017 18:09:29 +0100 Subject: lineedit: do not tab-complete any strings which have control characters function old new delta add_match 41 68 +27 Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index c0e35bb21..56e81404e 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -645,6 +645,18 @@ static void free_tab_completion_data(void) static void add_match(char *matched) { + unsigned char *p = (unsigned char*)matched; + while (*p) { + /* ESC attack fix: drop any string with control chars */ + if (*p < ' ' + || (!ENABLE_UNICODE_SUPPORT && *p >= 0x7f) + || (ENABLE_UNICODE_SUPPORT && *p == 0x7f) + ) { + free(matched); + return; + } + p++; + } matches = xrealloc_vector(matches, 4, num_matches); matches[num_matches] = matched; num_matches++; -- cgit v1.2.3-55-g6feb From 0a6772214002da55e982b06947320b8911a1975b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Nov 2017 13:38:12 +0100 Subject: lineedit: get terminal width before printing prompt Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 56e81404e..5624a7fc3 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2401,6 +2401,8 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman bb_error_msg("cur_history:%d cnt_history:%d", state->cur_history, state->cnt_history); #endif + /* Get width (before printing prompt) */ + cmdedit_termw = get_terminal_width(STDIN_FILENO); /* Print out the command prompt, optionally ask where cursor is */ parse_and_put_prompt(prompt); ask_terminal(); @@ -2410,8 +2412,6 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman S.SIGWINCH_handler.sa_flags = SA_RESTART; sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); - cmdedit_termw = get_terminal_width(STDIN_FILENO); - read_key_buffer[0] = 0; while (1) { /* -- cgit v1.2.3-55-g6feb