Browse Source

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.
Ivan Grokhotkov 3 years ago
parent
commit
eab33e7174
1 changed files with 3 additions and 2 deletions
  1. 3 2
      components/console/linenoise/linenoise.c

+ 3 - 2
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);