Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit fda68ac

Browse files
authored
Apply allowlist to source conversion (#3208)
* Apply allowlist to source conversion * Remove vestigial lifetime * Remove redundant clone
1 parent a720dd1 commit fda68ac

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/agent/coverage/examples/record.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn main() -> Result<()> {
8989
} else {
9090
let cmd = command(&args.command, None);
9191
let recorded = CoverageRecorder::new(cmd)
92-
.allowlist(allowlist)
92+
.allowlist(allowlist.clone())
9393
.loader(loader)
9494
.timeout(timeout)
9595
.record()?;
@@ -103,8 +103,8 @@ fn main() -> Result<()> {
103103

104104
match args.output {
105105
OutputFormat::ModOff => dump_modoff(&coverage)?,
106-
OutputFormat::Source => dump_source_line(&coverage)?,
107-
OutputFormat::Cobertura => dump_cobertura(&coverage)?,
106+
OutputFormat::Source => dump_source_line(&coverage, allowlist.source_files)?,
107+
OutputFormat::Cobertura => dump_cobertura(&coverage, allowlist.source_files)?,
108108
}
109109

110110
Ok(())
@@ -160,8 +160,8 @@ fn dump_modoff(coverage: &BinaryCoverage) -> Result<()> {
160160
Ok(())
161161
}
162162

163-
fn dump_source_line(binary: &BinaryCoverage) -> Result<()> {
164-
let source = coverage::source::binary_to_source_coverage(binary)?;
163+
fn dump_source_line(binary: &BinaryCoverage, allowlist: AllowList) -> Result<()> {
164+
let source = coverage::source::binary_to_source_coverage(binary, allowlist)?;
165165

166166
for (path, file) in &source.files {
167167
for (line, count) in &file.lines {
@@ -172,8 +172,8 @@ fn dump_source_line(binary: &BinaryCoverage) -> Result<()> {
172172
Ok(())
173173
}
174174

175-
fn dump_cobertura(binary: &BinaryCoverage) -> Result<()> {
176-
let source = coverage::source::binary_to_source_coverage(binary)?;
175+
fn dump_cobertura(binary: &BinaryCoverage, allowlist: AllowList) -> Result<()> {
176+
let source = coverage::source::binary_to_source_coverage(binary, allowlist)?;
177177
let cobertura: CoberturaCoverage = source.into();
178178

179179
println!("{}", cobertura.to_string()?);

src/agent/coverage/src/source.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use debuggable_module::loader::Loader;
1212
use debuggable_module::path::FilePath;
1313
use debuggable_module::{Module, Offset};
1414

15+
use crate::allowlist::AllowList;
1516
use crate::binary::BinaryCoverage;
1617

1718
pub use crate::binary::Count;
@@ -48,12 +49,16 @@ impl From<Line> for u32 {
4849
}
4950
}
5051

51-
pub fn binary_to_source_coverage(binary: &BinaryCoverage) -> Result<SourceCoverage> {
52+
pub fn binary_to_source_coverage(
53+
binary: &BinaryCoverage,
54+
allowlist: impl Into<Option<AllowList>>,
55+
) -> Result<SourceCoverage> {
5256
use std::collections::btree_map::Entry;
5357

5458
use symbolic::debuginfo::Object;
5559
use symbolic::symcache::{SymCache, SymCacheConverter};
5660

61+
let allowlist = allowlist.into().unwrap_or_default();
5762
let loader = Loader::new();
5863

5964
let mut source = SourceCoverage::default();
@@ -100,6 +105,11 @@ pub fn binary_to_source_coverage(binary: &BinaryCoverage) -> Result<SourceCovera
100105
};
101106

102107
if let Some(file) = location.file() {
108+
// Only include relevant inlinees.
109+
if !allowlist.is_allowed(&file.full_path()) {
110+
continue;
111+
}
112+
103113
let file_path = FilePath::new(file.full_path())?;
104114

105115
// We have a hit.

src/agent/onefuzz-task/src/tasks/coverage/generic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,11 @@ impl<'a> TaskContext<'a> {
449449

450450
async fn source_coverage(&self) -> Result<SourceCoverage> {
451451
// Must be owned due to `spawn_blocking()` lifetimes.
452+
let allowlist = self.allowlist.clone();
452453
let binary = self.coverage.clone();
453454

454455
// Conversion to source coverage heavy on blocking I/O.
455-
spawn_blocking(move || binary_to_source_coverage(&binary)).await?
456+
spawn_blocking(move || binary_to_source_coverage(&binary, allowlist.source_files)).await?
456457
}
457458
}
458459

0 commit comments

Comments
 (0)