Skip to content

Commit

Permalink
Fix aslr detection (#1673)
Browse files Browse the repository at this point in the history
A first fix from rustybug work
  • Loading branch information
xd009642 authored Jan 1, 2025
1 parent 5e885a1 commit 7df4d8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
From 2019 onwards, all notable changes to tarpaulin will be documented in this
file.

## [Unreleased]
### Changed
- ASLR detection was slightly broken - although it wouldn't break anything unless setting was broken as well.

## [0.31.4] 2024-12-31
### Added
- Added `--include-files` argument to only display coverage for the mentioned files (#1667)
Expand Down
26 changes: 15 additions & 11 deletions src/process_handling/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,9 @@ fn disable_aslr() -> nix::Result<()> {
}

fn is_aslr_enabled() -> bool {
// Create a Command instance with the 'cat' command and the path to the file as arguments
let output = Command::new("cat")
.arg("/proc/sys/kernel/random/boot_random")
.output()
.unwrap();

// Convert the output to a String and store it in a variable
let output_str = String::from_utf8(output.stdout).unwrap();

// Check if the output string is not '0' (case-insensitive) and return the result
output_str.trim().to_lowercase() != "0"
!personality::get()
.map(|x| x.contains(personality::Persona::ADDR_NO_RANDOMIZE))
.unwrap_or(true)
}

pub fn limit_affinity() -> nix::Result<()> {
Expand Down Expand Up @@ -120,3 +112,15 @@ pub fn execute(

unreachable!();
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn can_disable_aslr() {
assert!(is_aslr_enabled());
disable_aslr().unwrap();
assert!(!is_aslr_enabled());
}
}

0 comments on commit 7df4d8c

Please sign in to comment.