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
feat(lisdex): B38 - the published field named a metric it did not hold
CarterPerez-dev2f71f214ff6b
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/eval.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/eval.rsindex dc1a19d5..4685b45e 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/eval.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/eval.rs@@ -255,7 +255,7 @@ mod tests {extents: std::collections::BTreeMap::new(),},complexity: crate::rank::Complexity {- own: 0,+ danger: 0,accumulated: 0,undiscovered: 0,},diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/rank.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/rank.rsindex 351511d7..ce527921 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/rank.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/rank.rs@@ -18,8 +18,12 @@ pub const EXPORT_PUBLIC: f64 = 1.0;pub const EXPORT_INTERNAL: f64 = 0.0;#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize)]+// All three are DANGER, not cyclomatic complexity: `danger` is a function's own cyclomatic plus+// its loops, nested loops and maximum nesting, and the other two sum that over what it reaches.+// The first field was published as `own` while carrying `graph.danger()`, which named a+// different metric than it held in an artifact other people read.pub struct Complexity {- pub own: u32,+ pub danger: u32,pub accumulated: u32,pub undiscovered: u32,}@@ -293,7 +297,7 @@ mod tests {line: 1,exported: true,complexity: Complexity {- own: complexity,+ danger: complexity,accumulated: complexity,undiscovered: complexity,},@@ -455,7 +459,7 @@ mod tests {line: 1,exported: true,complexity: Complexity {- own: 2,+ danger: 2,accumulated: 2753,undiscovered: 2753,},diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/surface.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/surface.rsindex 95d19a6a..dbfaca34 100644--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/surface.rs+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/surface.rs@@ -367,7 +367,7 @@ pub fn analyze(options: &SurfaceOptions) -> Result<Surface, SurfaceError> {line: item.line,exported: exported_by(&item.name, &graph, library),complexity: Complexity {- own: graph.danger(&item.name),+ danger: graph.danger(&item.name),accumulated: graph.accumulated_danger(&item.name),undiscovered: graph.undiscovered_danger(&item.name, &reached),},@@ -565,7 +565,7 @@ void ctx_set_read(struct ctx *c, void *user, read_fn fn) { (void)c; (void)user;.find(|candidate| candidate.name == "ctx_read_header").unwrap();assert!(- reader.complexity.accumulated > reader.complexity.own,+ reader.complexity.accumulated > reader.complexity.danger,"chunk_parse is static and must still be counted: {:?}",reader.complexity);diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.shindex 90ed7b5e..51324ca8 100755--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh@@ -1035,6 +1035,40 @@ print(json.load(open(sys.argv[1]))["defined"])PY}+# B38. The field was published as `own` while carrying `graph.danger()` - own cyclomatic PLUS+# loops, nested loops and maximum nesting - so the artifact named a different metric than it+# held. Asserted on the serialized JSON rather than on the Rust struct, because the artifact is+# the thing other people read and a struct-level test would pass on a field serde renames.+# The candidate count is the liveness guard: an empty ranking would satisfy every `all()` below.+complexity_keys_of() {+ python3 - "$1" <<'PY'+import json, sys+data = json.load(open(sys.argv[1]))+candidates = data["ranking"]["candidates"]+if not candidates:+ print("VACUOUS")+ raise SystemExit(0)+named = all("danger" in c["complexity"] for c in candidates)+stale = any("own" in c["complexity"] for c in candidates)+# Read through .get so a renamed field is DIAGNOSED rather than raising a KeyError: a crash here+# printed nothing at all, and the gate failed with an empty reason instead of naming the field.+sane = all(+ c["complexity"]["accumulated"] >= c["complexity"].get("danger", 0) for c in candidates+)+print(f"n={len(candidates)} named={named} stale={stale} sane={sane}")+PY+}++B38_KEYS="$(complexity_keys_of "$OUT/libpng.json")"+if [ "$B38_KEYS" = "VACUOUS" ]; then+ bad "libpng ranked nothing, so the complexity-field assertion would pass on an empty list"+elif echo "$B38_KEYS" | grep -q 'named=True' && echo "$B38_KEYS" | grep -q 'stale=False' \+ && echo "$B38_KEYS" | grep -q 'sane=True'; then+ ok "every candidate publishes complexity.danger, none publishes the mislabelled own ($B38_KEYS)"+else+ bad "the published complexity fields are wrong: $B38_KEYS"+fi+# The fixture holds exactly seven bodies: four entry points, a_large's helper, z_small's# helper, and the one shared_helper the header gives both left.c and right.c. That count is# a three-way discriminator and the reason this stage does not compare left against right -