Skip to content

Commit

Permalink
Merge pull request #957 from GuillaumeGomez/fix-windows-panic
Browse files Browse the repository at this point in the history
Fix potential windows panic when getting process data
  • Loading branch information
GuillaumeGomez committed Mar 17, 2023
2 parents f82c205 + 86ca525 commit 6d26e8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/linux/process.rs
Expand Up @@ -675,10 +675,10 @@ fn get_uid_and_gid(file_path: &Path) -> Option<(uid_t, gid_t)> {
let mut gid = None;
for line in status_data.lines() {
if let Some(u) = f(line, "Uid:") {
assert!(uid.is_none());
debug_assert!(uid.is_none());
uid = Some(u);
} else if let Some(g) = f(line, "Gid:") {
assert!(gid.is_none());
debug_assert!(gid.is_none());
gid = Some(g);
} else {
continue;
Expand Down
6 changes: 4 additions & 2 deletions src/windows/process.rs
Expand Up @@ -690,8 +690,10 @@ unsafe fn get_process_data(
return Err("Unable to read process data");
}

// Documentation states that the function fails if not all data is accessible
assert_eq!(bytes_read, size);
// Documentation states that the function fails if not all data is accessible.
if bytes_read != size {
return Err("ReadProcessMemory returned unexpected number of bytes read");
}

buffer.set_len(size / 2);
buffer.push(0);
Expand Down

0 comments on commit 6d26e8c

Please sign in to comment.