summaryrefslogtreecommitdiff
path: root/runtime/permissions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/permissions.rs')
-rw-r--r--runtime/permissions.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/runtime/permissions.rs b/runtime/permissions.rs
index 9e97ac234..d1ee7f999 100644
--- a/runtime/permissions.rs
+++ b/runtime/permissions.rs
@@ -1194,6 +1194,29 @@ fn permission_prompt(message: &str) -> bool {
if !atty::is(atty::Stream::Stdin) || !atty::is(atty::Stream::Stderr) {
return false;
};
+
+ #[cfg(unix)]
+ fn clear_stdin() {
+ let r = unsafe { libc::tcflush(0, libc::TCIFLUSH) };
+ assert_eq!(r, 0);
+ }
+
+ #[cfg(not(unix))]
+ fn clear_stdin() {
+ unsafe {
+ let stdin = winapi::um::processenv::GetStdHandle(
+ winapi::um::winbase::STD_INPUT_HANDLE,
+ );
+ let flags =
+ winapi::um::winbase::PURGE_TXCLEAR | winapi::um::winbase::PURGE_RXCLEAR;
+ winapi::um::commapi::PurgeComm(stdin, flags);
+ }
+ }
+
+ // For security reasons we must consume everything in stdin so that previously
+ // buffered data cannot effect the prompt.
+ clear_stdin();
+
let opts = "[y/n (y = yes allow, n = no deny)] ";
let msg = format!(
"{} ️Deno requests {}. Allow? {}",