From a44bd300f006b74c09a74aff419b43912e114e0c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 29 Sep 2024 11:53:48 +0000 Subject: Ignore pending input before confirmation prompts Pressing ENTER for too long lets it end up in the input buffer which the confirmation prompt happily picks up and accepts as confirmation for deleting potentially half your system or doing other silly things. Ironically, this confirmation will also be silent in terms of output as it is likely erased by future progress reporting. Closes: #1082956 --- apt-private/private-output.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 4a946f2b8..0c56026a5 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -809,6 +810,12 @@ bool YnPrompt(char const * const Question, bool const Default, bool const ShowGl else _error->DumpErrors(c2o, GlobalError::NOTICE); } + // ignore pending input on terminal + if (not AssumeYes && not AssumeNo && isatty(STDIN_FILENO) == 1) + { + tcflush(STDIN_FILENO, TCIFLUSH); + std::cin.clear(); + } c2o << Question << std::flush; -- cgit v1.2.3-70-g09d2