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): B16 + the missing M5 exit gate - MSAN was unreachable, and M5 had no gate at all

CarterPerez-dev62c504ea004c
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 db5bb740..27dfc623 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
@@ -9,7 +9,7 @@ use std::time::Duration;
use clap::{Parser, Subcommand};
use lisdex_build::artifact;
-use lisdex_build::instrument::Instrumentation;
+use lisdex_build::instrument::{Instrumentation, SanitizerSet};
use lisdex_build::ladder::{self, BuildOptions};
use lisdex_build::layout::{BuildLayout, VARIANT_AFL, VARIANT_BENCH};
use lisdex_build::verify::{self, Requirements};
@@ -81,6 +81,23 @@ const LLM_PROBE_BALLOT: [&str; 2] = ["byte_buffer", "nul_terminated_string"];
const SAMPLE_CSV_HEADER: &str =
"relative_time,corpus_count,edges_found,execs_per_sec,total_execs,saved_crashes,map_size_pct";
+#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
+enum SanitizerChoice {
+ AddressUndefined,
+ Memory,
+ Off,
+}
+
+impl From<SanitizerChoice> for SanitizerSet {
+ fn from(choice: SanitizerChoice) -> Self {
+ match choice {
+ SanitizerChoice::AddressUndefined => SanitizerSet::AddressUndefined,
+ SanitizerChoice::Memory => SanitizerSet::Memory,
+ SanitizerChoice::Off => SanitizerSet::Off,
+ }
+ }
+}
+
#[derive(Parser)]
#[command(
name = "lisdex",
@@ -364,6 +381,13 @@ struct BuildArgs {
cflags: Vec<String>,
#[arg(long, help = "require magma canary symbols in the built artifacts")]
require_canaries: bool,
+ #[arg(
+ long,
+ value_enum,
+ default_value_t = SanitizerChoice::AddressUndefined,
+ help = "sanitizer set for this build; memory is a SEPARATE second build and cannot be combined with address"
+ )]
+ sanitizer: SanitizerChoice,
}
#[derive(clap::Args)]
@@ -1265,12 +1289,14 @@ fn build(args: &BuildArgs) -> Result<(), Box<dyn Error>> {
.join(", ")
);
+ let sanitizers = SanitizerSet::from(args.sanitizer);
let instrumentation = Instrumentation::instrumented()
+ .with_sanitizers(sanitizers)
.with_cmplog(args.cmplog)
.with_extra_cflags(args.cflags.clone());
let layout = BuildLayout::validated(&detected.root, args.work.join(BUILDS_DIR).join(&label))?;
- let requirements = Requirements::library()
+ let requirements = Requirements::for_sanitizers(sanitizers)
.with_cmplog(args.cmplog)
.with_magma_canaries(args.require_canaries);
let options = BuildOptions::new(
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/justfile b/PROJECTS/advanced/zero-day-vulnerability-scanner/justfile
index 7e95d464..010ed426 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/justfile
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/justfile
@@ -76,6 +76,12 @@ m4-gate:
m4-gate-reset:
docker compose -f dev.compose.yml exec toolchain bash scripts/m4-gate.sh reset
+m5-gate:
+ docker compose -f dev.compose.yml exec toolchain bash scripts/m5-gate.sh
+
+m5-gate-reset:
+ docker compose -f dev.compose.yml exec toolchain bash scripts/m5-gate.sh reset
+
m6-gate:
docker compose -f dev.compose.yml exec toolchain bash scripts/m6-gate.sh
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m5-gate.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m5-gate.sh
new file mode 100755
index 00000000..8bd85226
--- /dev/null
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m5-gate.sh
@@ -0,0 +1,257 @@
+#!/usr/bin/env bash
+# ©AngelaMos | 2026
+# m5-gate.sh
+
+# M5 is the LLM-booster milestone, RESCOPED 2026-07-29 by the doc-03 verify delta.
+#
+# The design's original M5 gate said "improves harness compile-rate over the deterministic
+# baseline". Doc 03 D1 showed that is GAMEABLE: CKGFuzzer's +19.8pp is a COMPILE-rate gain,
+# and four of lisdex's five measured failures compile fine and fail semantically, so the
+# check goes green on a harness that compiles and fuzzes handle plumbing. D1's prescription
+# is to gate on what the booster is allowed to DO instead.
+#
+# What M5 actually shipped is a doctrine, and this gate asserts the doctrine:
+# 1. keyless is not a degraded mode - the deterministic path plans harnesses with no model
+# 2. the booster is structurally unable to reach harness synthesis
+# 3. a model may only pick from a ballot the caller offered; anything else is discarded
+#
+# Every stage carries a negative control, because a refusal path that refuses everything and
+# an acceptance path that accepts everything both look green from one side.
+
+set -euo pipefail
+
+WORK="${MAGMA_WORK:-/opt/magma-work}"
+GATE="$WORK/m5"
+LISDEX_BIN="${CARGO_TARGET_DIR:-/cargo-target}/debug/lisdex"
+FAKE_PORT="${LISDEX_M5_FAKE_PORT:-47318}"
+FAKE_LOG="$GATE/fake-backend.log"
+TREE="$GATE/tree"
+
+PASS=0
+FAILURES=0
+
+log() { printf '\n[m5] %s\n' "$1"; }
+die() { printf '\n[m5] FAIL: %s\n' "$1" >&2; exit 1; }
+pass() { printf ' PASS %s\n' "$1"; PASS=$((PASS + 1)); }
+fail() { printf ' FAIL %s\n' "$1"; FAILURES=$((FAILURES + 1)); }
+
+FAKE_PID=""
+cleanup() {
+ if [ -n "$FAKE_PID" ]; then
+ kill "$FAKE_PID" 2>/dev/null || true
+ wait "$FAKE_PID" 2>/dev/null || true
+ fi
+}
+trap cleanup EXIT
+
+if [ "${1:-}" = "reset" ]; then
+ log "resetting $GATE"
+ rm -rf "$GATE"
+fi
+mkdir -p "$GATE"
+
+log "stage 1/4: build lisdex"
+cargo build -p lisdex
+[ -x "$LISDEX_BIN" ] || die "lisdex binary not found at $LISDEX_BIN"
+
+# ---------------------------------------------------------------------------
+log "stage 2/4: keyless is the product, not a degraded mode"
+# A tree with a plain byte-buffer entry point. The deterministic mechanisms of the
+# rescoped M5 (extent ownership, corpus binding) must plan it with NO model configured
+# and no API key in the environment.
+rm -rf "$TREE"
+mkdir -p "$TREE/include" "$TREE/src"
+cat > "$TREE/include/tree.h" <<'HEADER'
+#include <stddef.h>
+int tree_parse_blob(const unsigned char *data, size_t len);
+int tree_scan_header(const unsigned char *buf, size_t n);
+HEADER
+cat > "$TREE/src/tree.c" <<'SOURCE'
+#include "tree.h"
+int tree_parse_blob(const unsigned char *data, size_t len) {
+ int total = 0;
+ if (len < 4) { return -1; }
+ for (size_t i = 0; i < len; i++) {
+ if (data[i] == 0x7f) { total += 2; }
+ else if (data[i] == 0x1a) { total -= 1; }
+ else { total += 1; }
+ }
+ while (total > 1000) { total /= 2; }
+ switch (data[0]) { case 9: return 9; case 8: return 8; }
+ return total;
+}
+int tree_scan_header(const unsigned char *buf, size_t n) {
+ if (n < 2) { return -1; }
+ return buf[0] == 0x89 && buf[1] == 0x50;
+}
+SOURCE
+
+env -u LISDEX_LLM_ENDPOINT -u LISDEX_LLM_MODEL -u ANTHROPIC_API_KEY -u OPENAI_API_KEY \
+ "$LISDEX_BIN" harness "$TREE" --out "$GATE/keyless-out" --plan-only --top 5 \
+ > "$GATE/keyless.txt" 2>&1 || true
+
+PLANNED="$(grep -c 'PLANS' "$GATE/keyless.txt" 2>/dev/null || true)"
+if [ "${PLANNED:-0}" -gt 0 ]; then
+ pass "the deterministic path planned $PLANNED harness(es) with no model and no key configured"
+else
+ fail "keyless run planned nothing (see $GATE/keyless.txt); keyless must not be a degraded mode"
+fi
+
+# Negative control for stage 2: the SAME command against a tree with no readable
+# entry point must NOT report a plan, or "planned something" proves nothing.
+BARE="$GATE/bare"
+rm -rf "$BARE"
+mkdir -p "$BARE/include" "$BARE/src"
+cat > "$BARE/include/bare.h" <<'HEADER'
+struct bare_ctx;
+struct bare_ctx *bare_create(void);
+void bare_destroy(struct bare_ctx *c);
+HEADER
+cat > "$BARE/src/bare.c" <<'SOURCE'
+#include "bare.h"
+#include <stdlib.h>
+struct bare_ctx { int state; };
+struct bare_ctx *bare_create(void) { return (struct bare_ctx *)calloc(1, sizeof(struct bare_ctx)); }
+void bare_destroy(struct bare_ctx *c) { free(c); }
+SOURCE
+
+env -u LISDEX_LLM_ENDPOINT -u LISDEX_LLM_MODEL \
+ "$LISDEX_BIN" harness "$BARE" --out "$GATE/bare-out" --plan-only --top 5 \
+ > "$GATE/bare.txt" 2>&1 || true
+# Same measurable as the positive case, opposite direction: a keyword grep would let a
+# reworded banner decide the verdict, so both arms count PLANS lines.
+BARE_PLANNED="$(grep -c 'PLANS' "$GATE/bare.txt" 2>/dev/null || true)"
+if [ "${BARE_PLANNED:-0}" -eq 0 ]; then
+ pass "a constructor-only tree plans nothing, so the $PLANNED above is a real discrimination"
+else
+ fail "a constructor-only tree planned $BARE_PLANNED harness(es) (see $GATE/bare.txt)"
+fi
+
+# ---------------------------------------------------------------------------
+log "stage 3/4: the booster cannot reach harness synthesis"
+# The doctrine is that a model never widens a harness. That is a call-graph property,
+# so it is checked on the dependency edge AND on the shipped binary's symbols.
+if grep -q 'lisdex-llm' crates/lisdex-harness/Cargo.toml 2>/dev/null; then
+ fail "lisdex-harness declares a dependency on lisdex-llm; synthesis must not be able to call a model"
+else
+ pass "lisdex-harness declares no dependency on lisdex-llm"
+fi
+
+# The dependency check alone would pass if the edge moved somewhere synthesis still
+# reaches, so assert the reverse edge too: the llm crate must not pull in the
+# synthesizer and call it either.
+if grep -q 'lisdex-harness' crates/lisdex-llm/Cargo.toml 2>/dev/null; then
+ fail "lisdex-llm depends on lisdex-harness, so the booster sits inside the synthesis path"
+else
+ pass "lisdex-llm declares no dependency on lisdex-harness"
+fi
+
+# Negative control for the grep itself: it must be able to SEE a dependency that is
+# really there, or an always-false check would alibi both assertions above.
+if grep -q 'lisdex-surface' crates/lisdex-harness/Cargo.toml 2>/dev/null; then
+ pass "the dependency probe detects a dependency that IS declared (lisdex-surface)"
+else
+ fail "the dependency probe found no lisdex-surface edge, so it cannot detect an lisdex-llm edge either"
+fi
+
+# ---------------------------------------------------------------------------
+log "stage 4/4: a model may only choose from the ballot it was given"
+# A fake Ollama-protocol backend, so the adjudicator is driven through the SHIPPED
+# binary rather than a unit test. Two runs against the same code path: one where the
+# model answers ON the ballot, one where it answers off it. Both directions are
+# required - a path that always declines would pass the off-ballot check alone.
+cat > "$GATE/fake_backend.py" <<'PY'
+import json
+import os
+import sys
+from http.server import BaseHTTPRequestHandler, HTTPServer
+
+ANSWER = os.environ["FAKE_ANSWER"]
+MODEL = os.environ["FAKE_MODEL"]
+
+
+class Handler(BaseHTTPRequestHandler):
+ def _send(self, payload):
+ body = json.dumps(payload).encode()
+ self.send_response(200)
+ self.send_header("Content-Type", "application/json")
+ self.send_header("Content-Length", str(len(body)))
+ self.end_headers()
+ self.wfile.write(body)
+
+ def do_GET(self):
+ if self.path.startswith("/api/tags"):
+ self._send({"models": [{"name": MODEL}]})
+ else:
+ self.send_response(404)
+ self.end_headers()
+
+ def do_POST(self):
+ length = int(self.headers.get("Content-Length", 0))
+ self.rfile.read(length)
+ self._send({"response": ANSWER, "done": True})
+
+ def log_message(self, *args):
+ pass
+
+
+HTTPServer(("127.0.0.1", int(sys.argv[1])), Handler).serve_forever()
+PY
+
+FAKE_MODEL="gate-fake-model"
+
+run_ask() {
+ local answer="$1" outfile="$2"
+ FAKE_ANSWER="$answer" FAKE_MODEL="$FAKE_MODEL" \
+ python3 "$GATE/fake_backend.py" "$FAKE_PORT" >> "$FAKE_LOG" 2>&1 &
+ FAKE_PID=$!
+ local waited=0
+ until curl -sf "http://127.0.0.1:$FAKE_PORT/api/tags" >/dev/null 2>&1; do
+ sleep 0.2
+ waited=$((waited + 1))
+ [ "$waited" -gt 50 ] && break
+ done
+ LISDEX_LLM_ENDPOINT="http://127.0.0.1:$FAKE_PORT" LISDEX_LLM_MODEL="$FAKE_MODEL" \
+ "$LISDEX_BIN" llm --tier local --ask > "$outfile" 2>&1 || true
+ kill "$FAKE_PID" 2>/dev/null || true
+ wait "$FAKE_PID" 2>/dev/null || true
+ FAKE_PID=""
+}
+
+run_ask "byte_buffer" "$GATE/onballot.txt"
+if grep -q 'answered "byte_buffer"' "$GATE/onballot.txt"; then
+ pass "an on-ballot answer is accepted, so the adjudicator is not refusing everything"
+else
+ fail "an on-ballot answer was not accepted (see $GATE/onballot.txt)"
+fi
+
+run_ask "the src parameter is definitely a raw pointer to heap memory" "$GATE/offballot.txt"
+if grep -q 'not on the ballot' "$GATE/offballot.txt" \
+ && ! grep -q '^answered' "$GATE/offballot.txt"; then
+ pass "a free-text answer the caller never offered is discarded as a fabrication"
+else
+ fail "an off-ballot answer was not discarded (see $GATE/offballot.txt)"
+fi
+
+# The keyless tier must decline without contacting anything at all.
+"$LISDEX_BIN" llm --tier none --ask > "$GATE/none.txt" 2>&1 || true
+if grep -q 'no booster is configured' "$GATE/none.txt"; then
+ pass "the none tier declines and the deterministic answer stands"
+else
+ fail "the none tier did not decline cleanly (see $GATE/none.txt)"
+fi
+
+# ---------------------------------------------------------------------------
+log "RESULT"
+echo " passed: $PASS"
+echo " failed: $FAILURES"
+if [ "$FAILURES" -eq 0 ]; then
+ printf '\n[m5] M5 EXIT GATE PASSED\n'
+ printf ' CHECK 1 the deterministic path plans a harness with no model and no key\n'
+ printf ' CHECK 2 the booster is structurally unable to reach harness synthesis\n'
+ printf ' CHECK 3 an on-ballot answer is accepted and an off-ballot answer is discarded\n'
+ printf ' CHECK 4 the keyless tier declines without contacting a backend\n'
+ exit 0
+fi
+printf '\n[m5] M5 EXIT GATE FAILED: %s check(s)\n' "$FAILURES" >&2
+exit 1
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m6-gate.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m6-gate.sh
index a589ed06..f999311d 100755
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m6-gate.sh
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m6-gate.sh
@@ -42,11 +42,11 @@ fi
mkdir -p "$GATE"
-log "stage 1/6: build lisdex"
+log "stage 1/7: build lisdex"
cargo build -p lisdex
[ -x "$LISDEX_BIN" ] || die "lisdex binary not found at $LISDEX_BIN"
-log "stage 2/6: the campaign layer answers for itself"
+log "stage 2/7: the campaign layer answers for itself"
# The end-to-end campaign below cannot isolate the dictionary selector from the
# instance planner from the curve parser: they all feed one run. Each owns tests
# no other mechanism can satisfy.
@@ -56,7 +56,7 @@ else
fail "lisdex-fuzz tests (see $GATE_LOG)"
fi
-log "stage 3/6: a sustained multi-core campaign with a dictionary it chose itself"
+log "stage 3/7: a sustained multi-core campaign with a dictionary it chose itself"
rm -rf "$FINDINGS" "$DB"
"$LISDEX_BIN" fuzz --target "$TARGET" --cmplog "$CMPLOG" --seeds "$SEEDS" \
--findings "$FINDINGS" --db "$DB" --duration "$GATE_DURATION" \
@@ -121,7 +121,7 @@ else
fail "$OVER_CAP instance(s) loaded more than $MAX_DICTIONARIES dictionaries"
fi
-log "stage 4/6: the campaign recorded a coverage curve and execs/s"
+log "stage 4/7: the campaign recorded a coverage curve and execs/s"
CURVE="$("$LISDEX_BIN" coverage --findings "$FINDINGS" 2>&1)"
printf '%s\n' "$CURVE" > "$GATE/curve.txt"
if printf '%s' "$CURVE" | grep -q 'curve_instance main'; then
@@ -157,7 +157,7 @@ else
fail "the CSV export carried no sample"
fi
-log "stage 5/6: the corpus distils, and resuming continues rather than restarting"
+log "stage 5/7: the corpus distils, and resuming continues rather than restarting"
rm -rf "$DISTILLED"
if "$LISDEX_BIN" corpus --target "$TARGET" --input "$FINDINGS/main/queue" \
--output "$DISTILLED" > "$GATE/corpus.txt" 2>&1; then
@@ -195,7 +195,146 @@ else
fi
fi
-log "stage 6/6: the campaign still triages to the canary ground truth"
+log "stage 6/7: the memory sanitizer is a SEPARATE second build, and it finds what address misses"
+# MSAN and ASAN cannot coexist in one binary, which is the whole reason the design
+# calls for a second build. Two things have to hold: lisdex must actually PRODUCE an
+# MSAN artifact when asked, and that artifact must catch a class the ASAN build does
+# not. Measured while writing this stage: an uninitialised STACK read is folded away
+# at -O1 and above, so a probe built that way reports nothing and the check would be
+# inert at exactly the optimisation level real builds use. The probe below reads heap
+# memory through a noinline function with the pointer escaping to a global, which
+# survives -O0 through -O3.
+MSAN_DIR="$GATE/msan"
+rm -rf "$MSAN_DIR"
+mkdir -p "$MSAN_DIR"
+cat > "$MSAN_DIR/probe.c" <<'PROBE'
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+static unsigned char *g_buf;
+__attribute__((noinline)) static int read_one(const unsigned char *p, size_t i) {
+ return p[i];
+}
+int main(int argc, char **argv) {
+ size_t n = (size_t)argc * 64;
+ g_buf = (unsigned char *)malloc(n);
+ if (!g_buf) { return 0; }
+ memset(g_buf, 0, 8);
+ int v = read_one(g_buf, 40);
+ int rc = (v == 0x5a) ? 3 : 0;
+ printf("done %d %s\n", rc, argv[0]);
+ free(g_buf);
+ return rc;
+}
+PROBE
+
+MSAN_SRC="$MSAN_DIR/lib"
+mkdir -p "$MSAN_SRC"
+cp "$MSAN_DIR/probe.c" "$MSAN_SRC/probe.c"
+cat > "$MSAN_SRC/Makefile" <<'MAKE'
+all: libprobe.a
+probe.o: probe.c
+ $(CC) $(CFLAGS) -c -o probe.o probe.c
+libprobe.a: probe.o
+ $(AR) rcs libprobe.a probe.o
+MAKE
+
+if "$LISDEX_BIN" build "$MSAN_SRC" --work "$MSAN_DIR/work" --sanitizer memory \
+ > "$MSAN_DIR/build.log" 2>&1; then
+ pass "lisdex build --sanitizer memory completed"
+else
+ fail "lisdex could not produce an MSAN build (see $MSAN_DIR/build.log)"
+fi
+
+MSAN_LIB="$(find "$MSAN_DIR/work" -name 'libprobe.a' 2>/dev/null | head -1)"
+if [ -n "$MSAN_LIB" ]; then
+ MSAN_SYMS="$(llvm-nm "$MSAN_LIB" 2>/dev/null | grep -c '__msan' || true)"
+ ASAN_SYMS="$(llvm-nm "$MSAN_LIB" 2>/dev/null | grep -c '__asan' || true)"
+ if [ "$MSAN_SYMS" -gt 0 ] && [ "$ASAN_SYMS" -eq 0 ]; then
+ pass "the MSAN artifact carries $MSAN_SYMS msan symbol(s) and $ASAN_SYMS asan symbol(s): a separate second build"
+ else
+ fail "MSAN artifact has msan=$MSAN_SYMS asan=$ASAN_SYMS; a second build must carry one and not the other"
+ fi
+else
+ fail "no libprobe.a under $MSAN_DIR/work"
+fi
+
+# The other direction, so a build that silently ignored --sanitizer cannot pass:
+# the DEFAULT build of the same source must be the mirror image.
+if "$LISDEX_BIN" build "$MSAN_SRC" --work "$MSAN_DIR/work-asan" \
+ > "$MSAN_DIR/build-asan.log" 2>&1; then
+ ASAN_LIB="$(find "$MSAN_DIR/work-asan" -name 'libprobe.a' 2>/dev/null | head -1)"
+ A_MSAN="$(llvm-nm "$ASAN_LIB" 2>/dev/null | grep -c '__msan' || true)"
+ A_ASAN="$(llvm-nm "$ASAN_LIB" 2>/dev/null | grep -c '__asan' || true)"
+ if [ "$A_ASAN" -gt 0 ] && [ "$A_MSAN" -eq 0 ]; then
+ pass "the default build is the mirror image: asan=$A_ASAN msan=$A_MSAN"
+ else
+ fail "default build has asan=$A_ASAN msan=$A_MSAN, so --sanitizer changed nothing"
+ fi
+else
+ fail "the default build of the probe failed (see $MSAN_DIR/build-asan.log)"
+fi
+
+# Detection differential. This arm asserts the TOOLCHAIN property that makes a second
+# build worth building at all - MSAN reports a class ASAN cannot - and it drives
+# afl-clang-fast directly, so it does NOT exercise lisdex's own flag. The lisdex-side
+# claim is carried by the two artifact checks above, which are what redden if
+# --sanitizer stops doing anything.
+AFL_USE_MSAN=1 AFL_QUIET=1 afl-clang-fast -g -O2 -o "$MSAN_DIR/probe_msan" \
+ "$MSAN_DIR/probe.c" > "$MSAN_DIR/cc-msan.log" 2>&1 || true
+AFL_USE_ASAN=1 AFL_USE_UBSAN=1 AFL_QUIET=1 afl-clang-fast -g -O2 -o "$MSAN_DIR/probe_asan" \
+ "$MSAN_DIR/probe.c" > "$MSAN_DIR/cc-asan.log" 2>&1 || true
+
+MSAN_HIT=0
+ASAN_HIT=0
+if [ -x "$MSAN_DIR/probe_msan" ]; then
+ MSAN_HIT="$("$MSAN_DIR/probe_msan" 2>&1 | grep -c 'use-of-uninitialized-value' || true)"
+fi
+if [ -x "$MSAN_DIR/probe_asan" ]; then
+ ASAN_HIT="$("$MSAN_DIR/probe_asan" 2>&1 | grep -c 'use-of-uninitialized-value' || true)"
+fi
+
+if [ "$MSAN_HIT" -gt 0 ] && [ "$ASAN_HIT" -eq 0 ]; then
+ pass "the MSAN profile reports an uninitialised read the ASAN profile does not ($MSAN_HIT vs $ASAN_HIT)"
+else
+ fail "detection differential broken: msan=$MSAN_HIT asan=$ASAN_HIT; an MSAN build that finds nothing ASAN misses is not worth a second build"
+fi
+
+# Negative control: an initialised probe must NOT be reported, or the check above
+# would pass on a sanitizer that fires unconditionally.
+cat > "$MSAN_DIR/clean.c" <<'CLEAN'
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+static unsigned char *g_buf;
+__attribute__((noinline)) static int read_one(const unsigned char *p, size_t i) {
+ return p[i];
+}
+int main(int argc, char **argv) {
+ size_t n = (size_t)argc * 64;
+ g_buf = (unsigned char *)malloc(n);
+ if (!g_buf) { return 0; }
+ memset(g_buf, 0, n);
+ int v = read_one(g_buf, 40);
+ int rc = (v == 0x5a) ? 3 : 0;
+ printf("done %d %s\n", rc, argv[0]);
+ free(g_buf);
+ return rc;
+}
+CLEAN
+AFL_USE_MSAN=1 AFL_QUIET=1 afl-clang-fast -g -O2 -o "$MSAN_DIR/clean_msan" \
+ "$MSAN_DIR/clean.c" > "$MSAN_DIR/cc-clean.log" 2>&1 || true
+CLEAN_HIT=1
+if [ -x "$MSAN_DIR/clean_msan" ]; then
+ CLEAN_HIT="$("$MSAN_DIR/clean_msan" 2>&1 | grep -c 'use-of-uninitialized-value' || true)"
+fi
+if [ "$CLEAN_HIT" -eq 0 ]; then
+ pass "a fully initialised probe is NOT reported, so the differential is not a sanitizer that always fires"
+else
+ fail "MSAN reported an initialised read ($CLEAN_HIT), so the detection check proves nothing"
+fi
+
+log "stage 7/7: the campaign still triages to the canary ground truth"
# `lisdex crashes` prints one row per crash; the campaign itself prints the
# grouping, which is the number that says harvesting crossed every instance.
BUGS="$(awk '/^distinct_bugs/ {print $2}' "$CAMPAIGN_LOG")"
@@ -213,6 +352,7 @@ if [ "$FAILURES" -eq 0 ]; then
printf ' CHECK 2 the format dictionary is chosen from the corpus, and afl-fuzz confirms loading it\n'
printf ' CHECK 3 coverage curve and execs/s are recorded, and exportable\n'
printf ' CHECK 4 the corpus distils, and resuming continues the clock rather than restarting it\n'
+ printf ' CHECK 5 the memory sanitizer builds as a SEPARATE second artifact and reports a class address misses\n'
exit 0
fi
printf '\n[m6] M6 EXIT GATE FAILED: %s check(s)\n' "$FAILURES" >&2