From 6b5599bb1238bb923aeaa854aaa393f09173aa1d Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 3 May 2022 21:26:14 +0200 Subject: [PATCH] console: linenoiseProbe: check if response is valid Previously linenoiseProbe would accept any 4 byte response, even one that isn't expected. This adds a check that the first byte of the response is ESC. Suggested in https://github.com/espressif/esp-idf/issues/8839. --- components/console/linenoise/linenoise.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/console/linenoise/linenoise.c b/components/console/linenoise/linenoise.c index f074d67c99..4fec09c33a 100644 --- a/components/console/linenoise/linenoise.c +++ b/components/console/linenoise/linenoise.c @@ -1057,6 +1057,10 @@ int linenoiseProbe(void) { if (cb < 0) { continue; } + if (read_bytes == 0 && c != '\x1b') { + /* invalid response */ + break; + } read_bytes += cb; } /* Restore old mode */