Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can β€” learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company πŸ‘‡

feat(lisdex): B11 - a perfect build announced a loss that never happened

CarterPerez-dev2d4a47ce27a8
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs
index e7dd05f0..5be8cfaa 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-build/src/ladder.rs
@@ -131,6 +131,7 @@ pub struct BuildOutcome {
pub counts: SymbolCounts,
pub lto_bitcode: bool,
pub attempts: Vec<Attempt>,
+ pub unplanned: Vec<BuildSystem>,
pub degradation: Vec<String>,
}
@@ -770,22 +771,28 @@ pub fn build(
counts: SymbolCounts::default(),
lto_bitcode: false,
attempts: Vec::new(),
+ unplanned: Vec::new(),
degradation: Vec::new(),
};
- for system in detection.unsupported() {
- outcome.degradation.push(format!(
- "{} detected but lisdex plans no {} build",
- system.as_str(),
- system.as_str()
- ));
- }
+ outcome.unplanned = detection.unsupported();
let supported = detection.supported();
if supported.is_empty() {
- outcome
- .degradation
- .push("no supported build system detected in the source tree".to_owned());
+ let named = outcome
+ .unplanned
+ .iter()
+ .map(|system| system.as_str())
+ .collect::<Vec<&str>>()
+ .join(", ");
+ outcome.degradation.push(if named.is_empty() {
+ "no supported build system detected in the source tree".to_owned()
+ } else {
+ format!(
+ "no supported build system detected in the source tree; the only one(s) present \
+ are {named}, which lisdex plans no build for"
+ )
+ });
return Ok(outcome);
}
@@ -1029,9 +1036,42 @@ mod tests {
)
.unwrap();
assert!(!outcome.succeeded());
- assert_eq!(outcome.degradation.len(), 2);
- assert!(outcome.degradation[0].contains("bazel"));
- assert!(outcome.degradation[1].contains("no supported build system"));
+ assert_eq!(outcome.unplanned, vec![BuildSystem::Bazel]);
+ assert_eq!(outcome.degradation.len(), 1);
+ assert!(outcome.degradation[0].contains("no supported build system"));
+ assert!(
+ outcome.degradation[0].contains("bazel"),
+ "when the unplanned system IS the reason nothing built, the degradation must name \
+ it: {}",
+ outcome.degradation[0]
+ );
+ }
+
+ #[test]
+ fn an_unplanned_build_system_is_never_reported_as_degradation_when_another_one_is_planned() {
+ let dir = scratch("unplanned-alongside");
+ let layout = BuildLayout::new(&dir, dir.join("work"));
+ let outcome = build(
+ &detection(vec![BuildSystem::Bazel, BuildSystem::CMake], &[]),
+ &layout,
+ &Instrumentation::instrumented(),
+ &BuildOptions::new("afl", 1),
+ )
+ .unwrap();
+ assert_eq!(
+ outcome.unplanned,
+ vec![BuildSystem::Bazel],
+ "the unplanned system must still be reported somewhere, just not as a loss"
+ );
+ assert!(
+ !outcome
+ .degradation
+ .iter()
+ .any(|line| line.contains(BuildSystem::Bazel.as_str())),
+ "brotli ships 8 bazel files and a CMakeLists.txt, and a fully instrumented cmake \
+ build of it printed `degraded: bazel detected` when nothing was degraded: {:?}",
+ outcome.degradation
+ );
}
#[test]
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs
index 96a7afb2..4183c0b2 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs
@@ -1733,6 +1733,14 @@ fn build(args: &BuildArgs) -> Result<(), Box<dyn Error>> {
let outcome = ladder::build(&detected, &layout, &instrumentation, &options)?;
+ for system in &outcome.unplanned {
+ eprintln!(
+ "note: {} detected; lisdex plans no {} build",
+ system.as_str(),
+ system.as_str()
+ );
+ }
+
for line in &outcome.degradation {
eprintln!("degraded: {line}");
}