From 38a16e05d91ee5389d59a6f0044a57a9b257c537 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 11 Mar 2022 20:53:38 +0100 Subject: [PATCH 1/2] console: disable colored hints if CONFIG_LOG_COLORS is not set --- components/console/esp_console_repl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/console/esp_console_repl.c b/components/console/esp_console_repl.c index 5c098ff5c2..839029a03b 100644 --- a/components/console/esp_console_repl.c +++ b/components/console/esp_console_repl.c @@ -368,6 +368,8 @@ static esp_err_t esp_console_common_init(size_t max_cmdline_length, esp_console_ #if CONFIG_LOG_COLORS console_config.hint_color = atoi(LOG_COLOR_CYAN); +#else + console_config.hint_color = -1; #endif ret = esp_console_init(&console_config); if (ret != ESP_OK) { From c0b97b674939f1694249a6f15918fc585badadb9 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 11 Mar 2022 20:52:15 +0100 Subject: [PATCH 2/2] console: linenoise: fix usage of an uninitialized buffer Reported in https://github.com/espressif/esp-idf/issues/6440 The issue could occur if esp_console_config_t::hint_color was set to -1. --- components/console/linenoise/linenoise.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/console/linenoise/linenoise.c b/components/console/linenoise/linenoise.c index ecdbf3a366..f074d67c99 100644 --- a/components/console/linenoise/linenoise.c +++ b/components/console/linenoise/linenoise.c @@ -501,9 +501,10 @@ void refreshShowHints(struct abuf *ab, struct linenoiseState *l, int plen) { int hintmaxlen = l->cols-(plen+l->len); if (hintlen > hintmaxlen) hintlen = hintmaxlen; if (bold == 1 && color == -1) color = 37; - if (color != -1 || bold != 0) + if (color != -1 || bold != 0) { snprintf(seq,64,"\033[%d;%d;49m",bold,color); - abAppend(ab,seq,strlen(seq)); + abAppend(ab,seq,strlen(seq)); + } abAppend(ab,hint,hintlen); if (color != -1 || bold != 0) abAppend(ab,"\033[0m",4);