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 πŸ‘‡

fix(lisdex): B90 - 127 of 127 stored keys were dead and the bug count said 4, not 2

CarterPerez-dev4a17b50d6f23
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/crash.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/crash.rs
index a70350b3..e65d406f 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/crash.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/crash.rs
@@ -2,6 +2,7 @@
// crash.rs
use crate::campaign::CampaignId;
+use crate::report::SanitizerReport;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CrashId(pub i64);
@@ -30,6 +31,23 @@ impl Crash {
}
}
+ #[must_use]
+ pub fn from_report(
+ campaign_id: CampaignId,
+ input: impl Into<Vec<u8>>,
+ sanitizer_report: impl Into<String>,
+ ) -> Self {
+ let sanitizer_report = sanitizer_report.into();
+ let stack_hash =
+ SanitizerReport::parse(&sanitizer_report).and_then(|report| report.stack_hash());
+ Self {
+ campaign_id,
+ input: input.into(),
+ sanitizer_report,
+ stack_hash,
+ }
+ }
+
#[must_use]
pub fn campaign_id(&self) -> CampaignId {
self.campaign_id
@@ -55,6 +73,42 @@ impl Crash {
mod tests {
use super::*;
+ const KEYED_REPORT: &str = "\
+==14==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000018 at pc 0x4a1
+ #0 0x55a in png_handle_PLTE pngrutil.c:992:4
+";
+
+ const UNSYMBOLIZED_REPORT: &str = "\
+==12==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000018 at pc 0x4a1
+ #0 0x7f0c8a2 (/lib/x86_64-linux-gnu/libc.so.6+0x21b97)
+";
+
+ #[test]
+ fn from_report_derives_the_key_instead_of_taking_one_on_trust() {
+ let crash = Crash::from_report(CampaignId(1), b"input".to_vec(), KEYED_REPORT);
+ let expected = SanitizerReport::parse(KEYED_REPORT)
+ .and_then(|report| report.stack_hash())
+ .unwrap();
+ assert_eq!(crash.stack_hash(), Some(expected.as_str()));
+ }
+
+ #[test]
+ fn from_report_refuses_a_key_the_current_filter_cannot_produce() {
+ let crash = Crash::from_report(CampaignId(1), b"input".to_vec(), UNSYMBOLIZED_REPORT);
+ assert_eq!(
+ crash.stack_hash(),
+ None,
+ "every frame is unsymbolized, so the current algorithm refuses a key; a crash rehydrated from an older row must inherit that refusal rather than an obsolete key"
+ );
+ }
+
+ #[test]
+ fn from_report_on_an_unreproduced_crash_invents_nothing() {
+ let crash = Crash::from_report(CampaignId(1), b"junk".to_vec(), "");
+ assert_eq!(crash.stack_hash(), None);
+ assert_eq!(crash.sanitizer_report(), "");
+ }
+
#[test]
fn new_crash_exposes_all_fields() {
let crash = Crash::new(
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/store.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/store.rs
index f1752435..456c5d51 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/store.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/store.rs
@@ -31,7 +31,8 @@ const INSERT_CAMPAIGN_SQL: &str = "INSERT INTO campaigns (target, status) VALUES
const SELECT_CAMPAIGN_SQL: &str = "SELECT target, status FROM campaigns WHERE id = ?1";
const UPDATE_CAMPAIGN_STATUS_SQL: &str = "UPDATE campaigns SET status = ?1 WHERE id = ?2";
const INSERT_CRASH_SQL: &str = "INSERT INTO crashes (campaign_id, input, sanitizer_report, stack_hash) VALUES (?1, ?2, ?3, ?4)";
-const SELECT_CRASHES_SQL: &str = "SELECT campaign_id, input, sanitizer_report, stack_hash FROM crashes WHERE campaign_id = ?1 ORDER BY id";
+const SELECT_CRASHES_SQL: &str =
+ "SELECT campaign_id, input, sanitizer_report FROM crashes WHERE campaign_id = ?1 ORDER BY id";
#[derive(Debug, thiserror::Error)]
pub enum StoreError {
@@ -127,11 +128,10 @@ impl Store {
let mut stmt = self.conn.prepare(SELECT_CRASHES_SQL)?;
let crashes = stmt
.query_map(params![id.0], |row| {
- Ok(Crash::new(
+ Ok(Crash::from_report(
CampaignId(row.get::<_, i64>(0)?),
row.get::<_, Vec<u8>>(1)?,
row.get::<_, String>(2)?,
- row.get::<_, Option<String>>(3)?,
))
})?
.collect::<Result<Vec<_>, _>>()?;
@@ -142,6 +142,22 @@ impl Store {
#[cfg(test)]
mod tests {
use super::*;
+ use crate::dedup;
+
+ const KEYED_REPORT: &str = "\
+==14==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000018 at pc 0x4a1
+ #0 0x55a in png_handle_PLTE pngrutil.c:992:4
+";
+
+ const UNSYMBOLIZED_REPORT: &str = "\
+==12==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000018 at pc 0x4a1
+ #0 0x7f0c8a2 (/lib/x86_64-linux-gnu/libc.so.6+0x21b97)
+";
+
+ const OBSOLETE_KEY: &str = "2167ce84a15da0f82167ce84a15da0f82167ce84a15da0f82167ce84a15da0f8";
+
+ const SECOND_OBSOLETE_KEY: &str =
+ "b326ecf663a3ab1ab326ecf663a3ab1ab326ecf663a3ab1ab326ecf663a3ab1a";
#[test]
fn campaign_round_trips_through_store() {
@@ -174,17 +190,82 @@ mod tests {
fn crashes_round_trip_and_link_to_campaign() {
let store = Store::open_in_memory().unwrap();
let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();
- let crash = Crash::new(
- id,
- b"\x89PNG\r\n\x1a\n".to_vec(),
- "ERROR: AddressSanitizer: heap-buffer-overflow",
- Some("abc123".to_owned()),
- );
+ let crash = Crash::from_report(id, b"\x89PNG\r\n\x1a\n".to_vec(), KEYED_REPORT);
store.insert_crash(&crash).unwrap();
let crashes = store.crashes_for_campaign(id).unwrap();
assert_eq!(crashes, vec![crash]);
}
+ #[test]
+ fn a_stored_key_is_a_cache_and_the_report_is_the_truth() {
+ let store = Store::open_in_memory().unwrap();
+ let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();
+ store
+ .insert_crash(&Crash::new(
+ id,
+ b"input".to_vec(),
+ KEYED_REPORT,
+ Some(OBSOLETE_KEY.to_owned()),
+ ))
+ .unwrap();
+ let loaded = store.crashes_for_campaign(id).unwrap();
+ let current = Crash::from_report(id, b"input".to_vec(), KEYED_REPORT);
+ assert_ne!(
+ loaded[0].stack_hash(),
+ Some(OBSOLETE_KEY),
+ "a key written before a change to the frame filter is not comparable with one written after; measured on two real libpng campaigns, every one of 127 stored rows was invalidated by adding a single entry to NOISE_FRAME_EXACT"
+ );
+ assert_eq!(
+ loaded[0].stack_hash(),
+ current.stack_hash(),
+ "the retained report is the durable artifact, so a row must key the same as a crash harvested today from the same output"
+ );
+ }
+
+ #[test]
+ fn a_stored_key_the_current_algorithm_would_refuse_loads_as_none() {
+ let store = Store::open_in_memory().unwrap();
+ let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();
+ store
+ .insert_crash(&Crash::new(
+ id,
+ b"input".to_vec(),
+ UNSYMBOLIZED_REPORT,
+ Some(OBSOLETE_KEY.to_owned()),
+ ))
+ .unwrap();
+ let loaded = store.crashes_for_campaign(id).unwrap();
+ assert_eq!(
+ loaded[0].stack_hash(),
+ None,
+ "the algorithm got stricter and now refuses an all-unsymbolized stack; a stored key must not resurrect a bucket the current code declines to create"
+ );
+ }
+
+ #[test]
+ fn rows_written_either_side_of_a_filter_change_count_as_one_bug() {
+ let store = Store::open_in_memory().unwrap();
+ let id = store.insert_campaign(&Campaign::new("libpng")).unwrap();
+ for key in [OBSOLETE_KEY, SECOND_OBSOLETE_KEY] {
+ store
+ .insert_crash(&Crash::new(
+ id,
+ b"input".to_vec(),
+ KEYED_REPORT,
+ Some(key.to_owned()),
+ ))
+ .unwrap();
+ }
+ let loaded = store.crashes_for_campaign(id).unwrap();
+ let grouping = dedup::group_crashes(&loaded);
+ assert_eq!(
+ grouping.keyed_bugs(),
+ 1,
+ "the same crash stored under two algorithm versions is one bug, not two; counting stored keys across the two real campaigns reported 4 bugs where the canary ground truth says 2"
+ );
+ assert_eq!(grouping.groups()[0].len(), 2);
+ }
+
#[test]
fn crash_without_stack_hash_round_trips_as_null() {
let store = Store::open_in_memory().unwrap();
@@ -192,7 +273,11 @@ mod tests {
let crash = Crash::new(id, b"unreproduced".to_vec(), "", None);
store.insert_crash(&crash).unwrap();
let loaded = store.crashes_for_campaign(id).unwrap();
- assert_eq!(loaded[0].stack_hash(), None);
+ assert_eq!(
+ loaded[0].stack_hash(),
+ None,
+ "an unreproduced crash has no report to derive a key from, and the recompute must not invent one"
+ );
}
#[test]
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/runner.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/runner.rs
index d1789935..d97f6b25 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/runner.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/runner.rs
@@ -272,8 +272,11 @@ pub fn harvest(
problems.push(format!("{}: report truncated", input_path.display()));
}
let report = SanitizerReport::parse(&reproduction.output);
- let stack_hash = report.as_ref().and_then(SanitizerReport::stack_hash);
- if stack_hash.is_none() {
+ if report
+ .as_ref()
+ .and_then(SanitizerReport::stack_hash)
+ .is_none()
+ {
let reason = if report.is_some() {
UNSYMBOLIZED_REASON
} else {
@@ -284,12 +287,7 @@ pub fn harvest(
input_path.display()
));
}
- crashes.push(Crash::new(
- campaign_id,
- input,
- reproduction.output,
- stack_hash,
- ));
+ crashes.push(Crash::from_report(campaign_id, input, reproduction.output));
}
Ok((crashes, problems))