diff --git a/crates/ospect/src/os/windows.rs b/crates/ospect/src/os/windows.rs index 518bbedd..79a56010 100644 --- a/crates/ospect/src/os/windows.rs +++ b/crates/ospect/src/os/windows.rs @@ -66,19 +66,37 @@ pub fn version() -> std::io::Result { return Err(std::io::Error::last_os_error()); } - // TODO(@panhania): Migrate to `MaybeUninit::uninit_array` once stabilized. - let mut kernel32_path = [0; MAX_PATH as usize + 1]; + let mut kernel32_path_buf = { + [const { std::mem::MaybeUninit::::uninit() }; MAX_PATH as usize + 1] + }; + // SAFETY: We allocate a buffer of length `MAX_PATH + 1` and pass it to the // function given `MAX_PATH` as its size. The extra one element is required // to accommodate for the null terminator. See [1] for more details. // // [1]: https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamew let kernel32_path_len = unsafe { - GetModuleFileNameW(kernel32, kernel32_path.as_mut_ptr(), MAX_PATH) + GetModuleFileNameW( + kernel32, + kernel32_path_buf.as_mut_ptr().cast::(), + MAX_PATH, + ) }; if kernel32_path_len == 0 { return Err(std::io::Error::last_os_error()); } + + // SAFETY: We verified that the initialization of `kernel32_path_buf` + // succeeded, so we can assume that all the items up to and including the + // specified length are initialized. + let kernel32_path = unsafe { + // TODO(rust-lang/rust#63569): Use `MaybeUninit::slice_assume_init_ref` + // once stable. For now we just inline its definition. + &*(&kernel32_path_buf[0..=kernel32_path_len as usize] as *const [_] as *const [u16]) + }; + + // We do a sanity check to ensure that we really do have a null-terminator + // at the end. if kernel32_path[kernel32_path_len as usize] != 0 { return Err(std::io::ErrorKind::InvalidData.into()); } diff --git a/crates/rrg/src/startup.rs b/crates/rrg/src/startup.rs index 334c8d7a..bb50949f 100644 --- a/crates/rrg/src/startup.rs +++ b/crates/rrg/src/startup.rs @@ -3,8 +3,6 @@ // Use of this source code is governed by an MIT-style license that can be found // in the LICENSE file or at https://opensource.org/licenses/MIT. -// TODO(panhania): Add support for binary paths in the `Metadata` object. - /// Sends a system message with startup information to the GRR server. pub fn startup() { let startup = Startup::now(); @@ -30,16 +28,11 @@ impl Startup { /// Creates a startup information as of now. pub fn now() -> Startup { - // TODO(rust-lang/rust#91345): Simplify with `inspect_err`. - let path = { - match std::env::current_exe().and_then(std::fs::canonicalize) { - Ok(path) => Some(path), - Err(error) => { - log::error!("failed to obtain agent's path: {error}"); - None - } - } - }; + let path = std::env::current_exe().and_then(std::fs::canonicalize) + .inspect_err(|error| { + log::error!("failed to obtain agent's path: {error}") + }) + .ok(); Startup { metadata: Metadata::from_cargo(), diff --git a/proto/rrg.proto b/proto/rrg.proto index 65fc1425..ded2ffde 100644 --- a/proto/rrg.proto +++ b/proto/rrg.proto @@ -51,11 +51,8 @@ enum Action { // TODO: Define more actions that should be supported. - // TODO(https://github.com/stepancheg/rust-protobuf/issues/671): Uncomment - // once `reserved` is supported in enums. - // Reserved for user-defined actions. - // reserved 1024 to 2048; + reserved 1024 to 2048; } // An action request issued by the GRR server.