Skip to content
Open
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
2 changes: 1 addition & 1 deletion checksec.rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ scroll = "0.13.0"
serde = { version = "1.0.145", features = ["derive"] }
serde_derive = "1.0.145"
serde_json = "1.0.86"
sysinfo = "0.28.2"
sysinfo = "0.38.2"
flate2 = "1.1.2"
base64 = "0.22.1"
bincode = { version = "2.0.1", features = ["serde"] }
Expand Down
51 changes: 28 additions & 23 deletions checksec.rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ extern crate core;
extern crate goblin;
extern crate ignore;
extern crate serde_json;
extern crate sysinfo;

use clap::{
crate_authors, crate_description, crate_version, Arg, ArgAction, ArgGroup,
Expand All @@ -25,9 +24,7 @@ use memmap2::Mmap;
use rayon::iter::ParallelBridge;
use rayon::prelude::*;
use serde_json::{json, to_string_pretty};
use sysinfo::{
PidExt, ProcessExt, ProcessRefreshKind, RefreshKind, System, SystemExt,
};
use sysinfo::{ProcessRefreshKind, RefreshKind, System, UpdateKind};

use std::collections::HashMap;
#[cfg(all(target_os = "linux", feature = "elf"))]
Expand Down Expand Up @@ -643,7 +640,9 @@ fn parse_process_libraries(
.into_iter()
.filter(|m| m.flags.x)
.filter_map(|m| m.pathname)
.filter(|p| p.is_absolute() && p != process.exe())
.filter(|p| {
p.is_absolute() && process.exe().is_none_or(|exe| p != exe)
})
.map(|p| match p.file_name() {
Some(file_name) => match file_name.to_str() {
Some(file_name) => {
Expand Down Expand Up @@ -708,7 +707,15 @@ where
processes
.par_bridge()
.filter_map(|process| {
match parse(process.exe(), &mut Some(Arc::clone(&cache))) {
let Some(exe) = process.exe() else {
eprintln!(
"No executable path for process {} with ID {}",
process.name().to_string_lossy(),
process.pid()
);
return None;
};
match parse(exe, &mut Some(Arc::clone(&cache))) {
Err(err) => {
if let ParseError::IO(ref e) = err {
if e.kind() == ErrorKind::NotFound
Expand All @@ -720,7 +727,7 @@ where

eprintln!(
"Can not parse process {} with ID {}: {}",
process.name(),
process.name().to_string_lossy(),
process.pid(),
err
);
Expand Down Expand Up @@ -874,11 +881,12 @@ fn main() {
libraries,
);

let refresh_kind = RefreshKind::nothing().with_processes(
ProcessRefreshKind::nothing().with_cpu().with_exe(UpdateKind::Always),
);

if procall {
let system = System::new_with_specifics(
RefreshKind::new()
.with_processes(ProcessRefreshKind::new().with_cpu()),
);
let system = System::new_with_specifics(refresh_kind);

let procs = parse_processes(system.processes().values(), libraries);

Expand All @@ -894,10 +902,7 @@ fn main() {
}
})
.collect();
let system = System::new_with_specifics(
RefreshKind::new()
.with_processes(ProcessRefreshKind::new().with_cpu()),
);
let system = System::new_with_specifics(refresh_kind);

let procs = parse_processes(
procids
Expand All @@ -909,14 +914,17 @@ fn main() {
})
})
.filter(|process| {
if process.exe().is_file() {
if process.exe().is_some_and(Path::is_file) {
true
} else {
eprintln!(
"No valid executable found for process {} with ID {}: {}",
process.name(),
process.name().to_string_lossy(),
process.pid(),
process.exe().display()
match process.exe() {
Some(exe) => exe.display().to_string(),
None => "<unknown>".to_string(),
}
);
false
}
Expand All @@ -926,14 +934,11 @@ fn main() {

print_process_results(&Processes::new(procs), &settings);
} else if let Some(procname) = procname {
let system = System::new_with_specifics(
RefreshKind::new()
.with_processes(ProcessRefreshKind::new().with_cpu()),
);
let system = System::new_with_specifics(refresh_kind);

let procs = parse_processes(
system
.processes_by_name(procname)
.processes_by_name(OsStr::new(procname))
// TODO: processes_by_name() should return a Iterator implementing the trait Send
.collect::<Vec<&sysinfo::Process>>()
.into_iter(),
Expand Down