diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2021-09-09 08:38:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-09 08:38:47 -0400 |
commit | fb35cd0ef496fee9aa65daadf542057f18d6063f (patch) | |
tree | 68724c25f890567751a5545238912f2624670c50 /runtime | |
parent | d9476292929a680e364db403d6fc69cfb893599f (diff) |
fix: permission prompt stuffing (#11931)
Fixes #9750
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/Cargo.toml | 2 | ||||
-rw-r--r-- | runtime/permissions.rs | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 98983b5de..03a58fdd0 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -85,7 +85,7 @@ uuid = { version = "0.8.2", features = ["v4"] } [target.'cfg(windows)'.dependencies] fwdansi = "1.1.0" -winapi = { version = "0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] } +winapi = { version = "0.3.9", features = ["commapi", "knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] } [target.'cfg(unix)'.dependencies] nix = "0.22.1" 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? {}", |