From e7b0989a96e7c9d93fab6cad93d658754aaafc02 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Mon, 2 Dec 2024 16:03:41 +0100 Subject: [PATCH] Stop shell read loop if the input stream was closed (#36675) --- src/lib/shell/MainLoopDefault.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib/shell/MainLoopDefault.cpp b/src/lib/shell/MainLoopDefault.cpp index 6a3a6b300b53f3..30e748836b473c 100644 --- a/src/lib/shell/MainLoopDefault.cpp +++ b/src/lib/shell/MainLoopDefault.cpp @@ -57,6 +57,15 @@ size_t ReadLine(char * buffer, size_t max) break; } + // Stop the loop if the input stream is closed. + if (ret == 0) + { + if (line_sz > 0) + // Return current buffer if it is not empty. + buffer[line_sz++] = '\0'; + break; + } + if (ret != 1) continue;