summaryrefslogtreecommitdiff
path: root/apt-private
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2024-09-29 11:53:48 +0000
committerDavid Kalnischkies <david@kalnischkies.de>2024-09-29 11:53:48 +0000
commita44bd300f006b74c09a74aff419b43912e114e0c (patch)
tree24535d41de4ed2a1fed9c5ac1df63c789143e9f7 /apt-private
parent98ad351133592fe8ed8ff0f6aa311005c8c3dad8 (diff)
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
Diffstat (limited to 'apt-private')
-rw-r--r--apt-private/private-output.cc7
1 files changed, 7 insertions, 0 deletions
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 <langinfo.h>
#include <regex.h>
#include <sys/ioctl.h>
+#include <termios.h>
#include <unistd.h>
#include <sstream>
@@ -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;