diff --git a/Cargo.lock b/Cargo.lock index 8990d8ce9..5f84d01bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1788,7 +1788,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.51.1", ] [[package]] @@ -2893,7 +2893,7 @@ dependencies = [ "uuid", "wax", "which 5.0.0", - "windows 0.48.0", + "windows 0.52.0", "winreg", ] @@ -6136,11 +6136,12 @@ dependencies = [ [[package]] name = "windows" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ - "windows-targets 0.48.5", + "windows-core 0.52.0", + "windows-targets 0.52.0", ] [[package]] @@ -6152,6 +6153,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.45.0" diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index ab03bdc8d..eaf1ba3b9 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -122,7 +122,7 @@ features = [ "Win32_Security", "Win32_System_Threading", ] -version = "0.48" +version = "0.52" [features] plugin = ["nu-parser/plugin"] diff --git a/crates/nu-command/src/experimental/is_admin.rs b/crates/nu-command/src/experimental/is_admin.rs index ddd94da29..e2263fe8d 100644 --- a/crates/nu-command/src/experimental/is_admin.rs +++ b/crates/nu-command/src/experimental/is_admin.rs @@ -66,16 +66,17 @@ fn is_root_impl() -> bool { System::Threading::{GetCurrentProcess, OpenProcessToken}, }; - let mut handle = HANDLE::default(); let mut elevated = false; // Checks whether the access token associated with the current process has elevated privileges. // SAFETY: `elevated` only touched by safe code. - // `handle` lives long enough, initialized, mutated as out param, used, closed with validity check. + // `handle` lives long enough, initialized, mutated, used and closed with validity check. // `elevation` only read on success and passed with correct `size`. unsafe { + let mut handle = HANDLE::default(); + // Opens the access token associated with the current process. - if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut handle).as_bool() { + if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut handle).is_ok() { let mut elevation = TOKEN_ELEVATION::default(); let mut size = std::mem::size_of::() as u32; @@ -89,7 +90,7 @@ fn is_root_impl() -> bool { size, &mut size, ) - .as_bool() + .is_ok() { // Whether the token has elevated privileges. // Safe to read as `GetTokenInformation` will not write outside `elevation` and it succeeded @@ -100,7 +101,7 @@ fn is_root_impl() -> bool { if !handle.is_invalid() { // Closes the object handle. - CloseHandle(handle); + let _ = CloseHandle(handle); } }