Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve some of the TODO comments #77

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions crates/ospect/src/os/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,37 @@ pub fn version() -> std::io::Result<String> {
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::<u16>::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::<u16>(),
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());
}
Expand Down
17 changes: 5 additions & 12 deletions crates/rrg/src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(),
Expand Down
5 changes: 1 addition & 4 deletions proto/rrg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading