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 π
Go aicertificationcloud-engineeringcybercybersecuritycybersecurity-analystcybersecurity-certificationcybersecurity-certificationscybersecurity-educationcybersecurity-jobscybersecurity-portfoliocybersecurity-projectscybersecurity-toolsgrchackinglearningpentestingproject-repositoryprojetcspython
fix(lisdex): M7.4 - every double-free was its own bug, on every run
CarterPerez-dev4314ab834636
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/report.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/report.rsindex 6fb43c2e..1a2e4c58 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/report.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/report.rs@@ -20,6 +20,8 @@ const BUILD_ID_GROUP: &str = " (BuildId:";const MODULE_GROUP_OPEN: &str = " (";const MODULE_OFFSET_MARKER: &str = "+0x";const UNSYMBOLIZED_SYMBOL: &str = "<unknown>";+const REDACTED_ADDRESS: &str = "0xADDR";+const HEX_PREFIX: char = 'x';const MODULE_TAG_SEPARATOR: char = '@';const PATH_SEPARATOR: char = '/';const LOCATION_SEPARATOR: char = ':';@@ -162,7 +164,7 @@ fn find_header(lines: &[&str]) -> Option<(usize, String, String)> {for (index, line) in lines.iter().enumerate() {if let Some(found) = line.find(UBSAN_MARKER) {let message = line[found + UBSAN_MARKER.len()..].trim();- return Some((index, UBSAN_SANITIZER.to_owned(), message.to_owned()));+ return Some((index, UBSAN_SANITIZER.to_owned(), redact_addresses(message)));}}@@ -175,7 +177,29 @@ fn normalize_kind(remainder: &str) -> String {.filter_map(|marker| remainder.find(marker)).min().unwrap_or(remainder.len());- remainder[..cut].trim().to_owned()+ redact_addresses(remainder[..cut].trim())+}++fn redact_addresses(text: &str) -> String {+ let chars: Vec<char> = text.chars().collect();+ let mut out = String::with_capacity(text.len());+ let mut index = 0;+ while index < chars.len() {+ if chars[index] == '0' && chars.get(index + 1) == Some(&HEX_PREFIX) {+ let mut end = index + 2;+ while end < chars.len() && chars[end].is_ascii_hexdigit() {+ end += 1;+ }+ if end > index + 2 {+ out.push_str(REDACTED_ADDRESS);+ index = end;+ continue;+ }+ }+ out.push(chars[index]);+ index += 1;+ }+ out}fn parse_frames(lines: &[&str]) -> Vec<String> {@@ -632,6 +656,110 @@ pngrutil.c:1204:7: runtime error: left shift of negative value -1);}+ const DOUBLE_FREE: &str = "\+==53770==ERROR: AddressSanitizer: attempting double-free on 0x7b994ffe0040 in thread T0:+ #0 0x558474e42daa in free /work/target/doc07lab/asanlab.c:49:3+ #1 0x558474e42e11 in double_free /work/target/doc07lab/asanlab.c:49:3+";++ const ALLOC_DEALLOC_MISMATCH: &str = "\+==4==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs free) on 0x602000000018+ #0 0x4a1 in png_free pngmem.c:50:3+";++ const ODR_VIOLATION: &str = "\+==3==ERROR: AddressSanitizer: odr-violation (0x55a5aee02220):+ #0 0x4a1 in png_init pngread.c:10:1+";++ const UBSAN_POINTER_OVERFLOW: &str = "\+ubsanlab.c:26:15: runtime error: addition of unsigned offset to 0x558d605072e0 overflowed to 0x558d605072df+ #0 0x55a in pointer_overflow ubsanlab.c:26:15+";++ fn rebased(text: &str) -> String {+ text.replace("0x7b994ffe0040", "0x7f1122334455")+ .replace("0x602000000018", "0x7f2233445566")+ .replace("0x55a5aee02220", "0x7f3344556677")+ .replace("0x558d605072e0", "0x7f4455667788")+ .replace("0x558d605072df", "0x7f5566778899")+ }++ #[test]+ fn a_double_free_kind_does_not_carry_the_heap_address() {+ let report = SanitizerReport::parse(DOUBLE_FREE).unwrap();+ assert!(+ report.kind().contains("double-free"),+ "the kind must still name the error: {:?}",+ report.kind()+ );+ assert!(+ !report.kind().contains("0x7b994ffe0040"),+ "the kind is hashed FIRST into stack_hash, so a heap address in it gives every double-free crash its own bug: {:?}",+ report.kind()+ );+ }++ #[test]+ fn a_double_free_hashes_the_same_across_runs() {+ let first = SanitizerReport::parse(DOUBLE_FREE).unwrap();+ let moved = SanitizerReport::parse(&rebased(DOUBLE_FREE)).unwrap();+ assert_ne!(+ DOUBLE_FREE,+ rebased(DOUBLE_FREE),+ "the fixture must actually be rebased or this proves nothing"+ );+ assert!(first.stack_hash().is_some());+ assert_eq!(+ first.stack_hash(),+ moved.stack_hash(),+ "measured on the real captured dfree report: the key moved from 5c9d0c167d555207 to ed469ec955f2723f when only the heap address changed, so one bug counted as one per crash"+ );+ }++ #[test]+ fn the_grammars_that_park_an_address_outside_on_address_are_all_stabilised() {+ for text in [+ ALLOC_DEALLOC_MISMATCH,+ ODR_VIOLATION,+ UBSAN_POINTER_OVERFLOW,+ ] {+ let first = SanitizerReport::parse(text).unwrap();+ let moved = SanitizerReport::parse(&rebased(text)).unwrap();+ assert_ne!(text, rebased(text), "fixture must be rebased");+ assert_eq!(+ first.kind(),+ moved.kind(),+ "ASAN has 24 non-generic error kinds and they do not share the generic ' on address ' shape, so cutting at two markers can never cover them: {:?}",+ first.kind()+ );+ }+ }++ #[test]+ fn redaction_leaves_the_generic_grammar_untouched() {+ assert_eq!(+ SanitizerReport::parse(STACK_OVERFLOW).unwrap().kind(),+ "stack-buffer-overflow"+ );+ assert_eq!(+ SanitizerReport::parse(PNG003_CANARY).unwrap().kind(),+ "SEGV"+ );+ assert_eq!(+ SanitizerReport::parse(UBSAN_ONLY).unwrap().kind(),+ "left shift of negative value -1",+ "a description with no address must survive redaction unchanged"+ );+ }++ #[test]+ fn a_bare_0x_that_is_not_an_address_is_left_alone() {+ assert_eq!(redact_addresses("value 0x and 0xZZ"), "value 0x and 0xZZ");+ assert_eq!(redact_addresses("no hex here"), "no hex here");+ assert_eq!(redact_addresses("0xdeadbeef"), REDACTED_ADDRESS);+ }+#[test]fn anchored_lines_drop_everything_above_the_header() {let anchored = anchored_lines(PNG003_CANARY).unwrap();