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): B81 - a double pointer is two obligations, and only the canonical type tells them apart

CarterPerez-deva784ea851cd2
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/plan.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/plan.rs
index 7710c3b0..0c3c83e9 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/plan.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/plan.rs
@@ -13,6 +13,7 @@ pub const OUT_LEN_LOCAL: &str = "lisdex_out_len";
pub const OUT_CAPACITY: &str = "LISDEX_OUT_CAPACITY";
pub const MAX_OUT_BYTES: usize = 65536;
pub const AUX_LOCAL: &str = "lisdex_aux";
+pub const FILLED_LOCAL: &str = "lisdex_filled";
pub const AUX_CAPACITY: &str = "LISDEX_AUX_CAPACITY";
// lz4's own decompress_fuzzer.c uses `64 * 1024 - 1` for its large external dictionary, so
// this is that size rather than a round number: a dictionary at or above 64 KiB takes a
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/search.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/search.rs
index 9f25b8cf..8a69f776 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/search.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/search.rs
@@ -357,6 +357,7 @@ mod tests {
.iter()
.map(|function| Extension {
function: (*function).to_owned(),
+ declares: Vec::new(),
call: Stmt::Call {
function: (*function).to_owned(),
args: vec![Value::Local("ctx".to_owned())],
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/synth.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/synth.rs
index 481a8442..4775eb78 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/synth.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/synth.rs
@@ -11,7 +11,7 @@ use lisdex_surface::signature::{
Analysis, Fuzzability, Param, ParamRole, Pointee, Shape, handle_key,
};
-use crate::plan::{Binding, HarnessPlan, Init, OUT_LEN_LOCAL, Stmt, Value};
+use crate::plan::{Binding, FILLED_LOCAL, HarnessPlan, Init, OUT_LEN_LOCAL, Stmt, Value};
pub const CONTEXT_LOCAL: &str = "ctx";
pub const RESULT_LOCAL: &str = "rc";
@@ -331,12 +331,61 @@ fn is_double_pointer(param: &Param) -> bool {
matches!(
&param.shape,
Shape::Pointer {
- pointee: Pointee::Pointer,
+ pointee: Pointee::Pointer(_),
..
}
)
}
+// `archive_read_next_header(struct archive *, struct archive_entry **)` is not the shape B67
+// refuses. The LIBRARY allocates the entry and writes its address into a slot; the harness owns
+// nothing but the `struct archive_entry *entry = NULL;` local it passes the address of, and it
+// never dereferences what comes back. That is a fact the headers state, the same way an output
+// buffer the harness allocated states its own capacity.
+//
+// Two conditions, and both are load-bearing. The target one indirection down must be a RECORD,
+// because `unsigned char **dstPlanes` and `png_bytepp row` are the opposite obligation - the
+// caller allocates an array and the library reads it - and canonical types are what tell them
+// apart: `png_bytep *` spells a record and IS `unsigned char **`. And the inner type has to be
+// SPELLABLE by removing one indirection from what the header wrote, because a declaration the
+// harness cannot spell is one it cannot emit; `png_sPLT_tpp` hides both stars in a typedef and
+// is refused rather than guessed at, exactly as `indirect_extent_local` refuses.
+fn filled_by_library(param: &Param) -> Option<String> {
+ signature::record_behind_two_pointers(&param.shape)?;
+ let inner = param.spelling.trim().strip_suffix('*')?.trim();
+ (!inner.is_empty()).then(|| inner.to_owned())
+}
+
+// Which parameters the library fills in, and what the harness must declare for each. Shared by
+// the entry point and by an upward step so both spell the same local for the same signature.
+//
+// `standing` is how many such locals the plan already declares. Without it a step that takes a
+// library-filled out-param would redeclare the entry point's `lisdex_filled` in the same block,
+// which either shadows a slot an earlier call still refers to or does not compile at all.
+fn filled_locals(
+ params: &[Param],
+ roles: &[ParamRole],
+ standing: usize,
+) -> BTreeMap<usize, (String, String)> {
+ let mut found = BTreeMap::new();
+ for (index, (param, role)) in params.iter().zip(roles).enumerate() {
+ if !matches!(role, ParamRole::Output | ParamRole::Context) {
+ continue;
+ }
+ let Some(ty) = filled_by_library(param) else {
+ continue;
+ };
+ let position = standing + found.len();
+ let local = if position == 0 {
+ FILLED_LOCAL.to_owned()
+ } else {
+ format!("{FILLED_LOCAL}{position}")
+ };
+ found.insert(index, (ty, local));
+ }
+ found
+}
+
fn cast_for(param: &Param) -> Result<Option<String>, Refusal> {
let label = || param.name.clone().unwrap_or_else(|| param.spelling.clone());
match &param.shape {
@@ -476,11 +525,39 @@ fn primary_buffer(analysis: &Analysis) -> Option<usize> {
.position(|role| *role == ParamRole::Buffer)
}
+fn bind_all(
+ candidate: &Candidate,
+ locals: &BTreeMap<String, Held>,
+ filled: &BTreeMap<usize, (String, String)>,
+) -> Result<Vec<Value>, Refusal> {
+ candidate
+ .params
+ .iter()
+ .zip(&candidate.analysis.roles)
+ .enumerate()
+ .map(|(index, (param, role))| {
+ bind(index, param, *role, locals, filled, &candidate.analysis)
+ })
+ .collect()
+}
+
+fn filled_declarations(filled: &BTreeMap<usize, (String, String)>) -> Vec<Stmt> {
+ filled
+ .values()
+ .map(|(ty, local)| Stmt::Declare {
+ ty: ty.clone(),
+ name: local.clone(),
+ init: Init::Null,
+ })
+ .collect()
+}
+
fn bind(
index: usize,
param: &Param,
role: ParamRole,
locals: &BTreeMap<String, Held>,
+ filled: &BTreeMap<usize, (String, String)>,
analysis: &Analysis,
) -> Result<Value, Refusal> {
let label = param.name.clone().unwrap_or_else(|| param.spelling.clone());
@@ -583,7 +660,10 @@ fn bind(
}
ParamRole::Output | ParamRole::Context => {
if is_double_pointer(param) {
- return Err(Refusal::UnsizedOutParam { param: label });
+ return filled
+ .get(&index)
+ .map(|(_, local)| Value::AddressOf(local.clone()))
+ .ok_or(Refusal::UnsizedOutParam { param: label });
}
// Binding every context param to one shared local passed a small struct's
// address where a large one was expected and produced a real ASAN
@@ -846,6 +926,10 @@ fn replay_setup(
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Extension {
pub function: String,
+ // A step whose out-param the library fills needs its own NULL local, and the step is the
+ // only thing that knows the local exists. Carried here rather than hoisted into the plan
+ // so a step that is later rejected takes its declaration with it.
+ pub declares: Vec<Stmt>,
pub call: Stmt,
}
@@ -907,6 +991,7 @@ pub fn upward_steps(
);
let mut steps: Vec<Extension> = Vec::new();
+ let mut declared = filled_locals(&candidate.params, &candidate.analysis.roles, 0).len();
for name in tail_run(sequence, &candidate.name) {
if steps.len() == MAX_UPWARD_STEPS {
break;
@@ -947,11 +1032,12 @@ pub fn upward_steps(
break;
}
let analysis = signature::analyze_named(name, params, &BTreeSet::new());
+ let filled = filled_locals(params, &analysis.roles, declared);
let bound: Result<Vec<Value>, Refusal> = params
.iter()
.zip(&analysis.roles)
.enumerate()
- .map(|(index, (param, role))| bind(index, param, *role, &locals, &analysis))
+ .map(|(index, (param, role))| bind(index, param, *role, &locals, &filled, &analysis))
.collect();
let Ok(args) = bound else {
break;
@@ -959,8 +1045,10 @@ pub fn upward_steps(
if !args.iter().all(is_replayable_value) {
break;
}
+ declared += filled.len();
steps.push(Extension {
function: name.clone(),
+ declares: filled_declarations(&filled),
call: Stmt::Call {
function: name.clone(),
args,
@@ -1046,6 +1134,9 @@ pub fn extend(plan: &HarnessPlan, steps: &[Extension]) -> HarnessPlan {
built = built.with(statement.clone());
}
for step in steps {
+ for declaration in &step.declares {
+ built = built.with(declaration.clone());
+ }
built = built.with(step.call.clone());
}
for statement in &plan.body[cut..] {
@@ -1076,21 +1167,17 @@ pub fn plan_candidate_with(
opening,
} = resolve_contexts(candidate, vocabulary)?;
- let mut args = Vec::with_capacity(candidate.params.len());
- for (index, (param, role)) in candidate
- .params
- .iter()
- .zip(&candidate.analysis.roles)
- .enumerate()
- {
- args.push(bind(index, param, *role, &locals, &candidate.analysis)?);
- }
+ let filled = filled_locals(&candidate.params, &candidate.analysis.roles, 0);
+ let args = bind_all(candidate, &locals, &filled)?;
let mut emitted = BTreeSet::new();
let mut base = HarnessPlan::new(candidate.name.clone()).with_include(include);
if let Some(statement) = indirect_extent_local(candidate) {
base = base.with(statement);
}
+ for statement in filled_declarations(&filled) {
+ base = base.with(statement);
+ }
for statement in opening {
if let Stmt::Call { function, .. } = &statement {
emitted.insert(function.clone());
@@ -1666,12 +1753,45 @@ mod tests {
assert!(steps.is_empty(), "{steps:?}");
}
- // The measured gap, and the reason the climb STOPS rather than skips. libarchive's real
- // tail is `archive_read_next_header, archive_entry_pathname, archive_entry_size,
- // archive_read_data`; the first call takes `struct archive_entry **`, which bind refuses,
- // and `archive_read_data` behind it would read from a stream whose header was never read.
+ // The measured gap, and the reason the climb STOPS rather than skips. A call whose out-param
+ // the caller must SIZE cannot be copied - `unsigned char **planes` is an array of plane
+ // pointers the harness would have to allocate - and `archive_read_data` behind it would read
+ // from a stream whose header was never read.
#[test]
fn a_call_the_climb_cannot_copy_stops_it_rather_than_being_skipped() {
+ let mut vocabulary = replayable_archive_vocabulary();
+ vocabulary.functions.insert(
+ "archive_read_planes".to_owned(),
+ vec![
+ archive_handle(),
+ param(
+ "planes",
+ "unsigned char **",
+ Shape::Pointer {
+ pointee: Pointee::Pointer(Box::new(Pointee::UnsignedChar)),
+ is_const: false,
+ },
+ ),
+ ],
+ );
+ let steps = upward_steps(
+ &open_memory(),
+ &vocabulary,
+ &[
+ "archive_read_open_memory".to_owned(),
+ "archive_read_planes".to_owned(),
+ "archive_read_data".to_owned(),
+ ],
+ );
+ assert!(steps.is_empty(), "{steps:?}");
+ }
+
+ // The same fixture with the ONE thing B81 changed: the target one indirection down is a
+ // record, so the library allocates it and the harness owns only the NULL local it passes the
+ // address of. Paired with the test above deliberately - the two differ in nothing but the
+ // inner pointee, so a rule that stopped asking the question would move both.
+ #[test]
+ fn the_climb_copies_a_call_whose_out_param_the_library_fills() {
let mut vocabulary = replayable_archive_vocabulary();
vocabulary.functions.insert(
"archive_read_next_header".to_owned(),
@@ -1681,7 +1801,9 @@ mod tests {
"entry",
"struct archive_entry **",
Shape::Pointer {
- pointee: Pointee::Pointer,
+ pointee: Pointee::Pointer(Box::new(Pointee::Record(
+ "archive_entry".to_owned(),
+ ))),
is_const: false,
},
),
@@ -1693,10 +1815,136 @@ mod tests {
&[
"archive_read_open_memory".to_owned(),
"archive_read_next_header".to_owned(),
- "archive_read_data".to_owned(),
],
);
- assert!(steps.is_empty(), "{steps:?}");
+ assert_eq!(steps.len(), 1, "{steps:?}");
+ assert_eq!(steps[0].function, "archive_read_next_header");
+ assert_eq!(
+ steps[0].declares,
+ vec![Stmt::Declare {
+ ty: "struct archive_entry *".to_owned(),
+ name: FILLED_LOCAL.to_owned(),
+ init: Init::Null,
+ }]
+ );
+ assert_eq!(
+ steps[0].call,
+ Stmt::Call {
+ function: "archive_read_next_header".to_owned(),
+ args: vec![
+ Value::Local("ctx".to_owned()),
+ Value::AddressOf(FILLED_LOCAL.to_owned()),
+ ],
+ capture: None,
+ }
+ );
+ }
+
+ // The second half of `filled_by_library`, isolated. libpng writes `png_get_sPLT(..,
+ // png_sPLT_tpp entries)`, where the record IS behind two pointers but BOTH stars live inside
+ // the typedef, so removing one indirection from what the header wrote yields nothing to
+ // declare. A rule that answered the record question alone would emit a local it cannot spell.
+ #[test]
+ fn a_library_filled_out_param_whose_type_hides_both_stars_in_a_typedef_is_refused() {
+ let entries = param(
+ "entries",
+ "png_sPLT_tpp",
+ Shape::Pointer {
+ pointee: Pointee::Pointer(Box::new(Pointee::Record("png_sPLT_t".to_owned()))),
+ is_const: false,
+ },
+ );
+ assert_eq!(filled_by_library(&entries), None);
+ assert_eq!(
+ filled_locals(&[entries], &[ParamRole::Output], 0),
+ BTreeMap::new()
+ );
+ }
+
+ // The `standing` offset, isolated. The entry point already declares `lisdex_filled`, so the
+ // step has to declare `lisdex_filled1` - a second declaration of the same name in one block
+ // either shadows the slot the entry call still refers to or does not compile at all.
+ #[test]
+ fn a_step_numbers_its_filled_local_past_the_one_the_entry_point_declares() {
+ let entry_out = || {
+ param(
+ "first",
+ "struct archive_entry **",
+ Shape::Pointer {
+ pointee: Pointee::Pointer(Box::new(Pointee::Record(
+ "archive_entry".to_owned(),
+ ))),
+ is_const: false,
+ },
+ )
+ };
+ let opener = candidate(
+ "archive_open_entry",
+ vec![
+ archive_handle(),
+ param(
+ "buff",
+ "const void *",
+ Shape::Pointer {
+ pointee: Pointee::Void,
+ is_const: true,
+ },
+ ),
+ param("size", "size_t", Shape::Integral),
+ entry_out(),
+ ],
+ vec![
+ ParamRole::Context,
+ ParamRole::Buffer,
+ ParamRole::Length,
+ ParamRole::Context,
+ ],
+ Fuzzability::CastBuffer,
+ Returns::default(),
+ );
+ let mut vocabulary = replayable_archive_vocabulary();
+ vocabulary.functions.insert(
+ "archive_read_next_header".to_owned(),
+ vec![archive_handle(), entry_out()],
+ );
+ let sequence = [
+ "archive_open_entry".to_owned(),
+ "archive_read_next_header".to_owned(),
+ ];
+
+ let plans = plan_candidate_with(&opener, "archive.h", &vocabulary, &sequence).unwrap();
+ assert!(
+ plans[0].body.contains(&Stmt::Declare {
+ ty: "struct archive_entry *".to_owned(),
+ name: FILLED_LOCAL.to_owned(),
+ init: Init::Null,
+ }),
+ "{:?}",
+ plans[0].body
+ );
+
+ let steps = upward_steps(&opener, &vocabulary, &sequence);
+ assert_eq!(steps.len(), 1, "{steps:?}");
+ assert_eq!(
+ steps[0].declares,
+ vec![Stmt::Declare {
+ ty: "struct archive_entry *".to_owned(),
+ name: format!("{FILLED_LOCAL}1"),
+ init: Init::Null,
+ }]
+ );
+ let extended = extend(&plans[0], &steps);
+ assert_eq!(
+ extended
+ .body
+ .iter()
+ .filter(|statement| matches!(statement, Stmt::Declare { name, .. }
+ if name.starts_with(FILLED_LOCAL)))
+ .count(),
+ 2,
+ "{:?}",
+ extended.body
+ );
}
// Isolates the invented-value ban. `archive_read_set_format(a, int)` takes our handle and
@@ -3024,7 +3272,7 @@ mod tests {
"row_pointers",
"png_bytepp",
Shape::Pointer {
- pointee: Pointee::Pointer,
+ pointee: Pointee::Pointer(Box::new(Pointee::UnsignedChar)),
is_const: false,
},
),
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/extract.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/extract.rs
index ea1d5193..86bca1ee 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/extract.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/extract.rs
@@ -8,6 +8,7 @@ use std::sync::{Mutex, PoisonError};
use clang::diagnostic::{Diagnostic, Severity};
use clang::{Clang, Entity, EntityKind, Index, Type, TypeKind};
+use crate::signature;
use crate::signature::{Param, Pointee, Returns, Shape, handle_key};
static PARSE_LOCK: Mutex<()> = Mutex::new(());
@@ -225,7 +226,9 @@ fn pointee_of(ty: &Type) -> Pointee {
TypeKind::Void => Pointee::Void,
TypeKind::Record => Pointee::Record(record_name(ty)),
TypeKind::FunctionPrototype | TypeKind::FunctionNoPrototype => Pointee::Function,
- TypeKind::Pointer => Pointee::Pointer,
+ TypeKind::Pointer => ty.get_pointee_type().map_or(Pointee::Other, |inner| {
+ Pointee::Pointer(Box::new(pointee_of(&inner.get_canonical_type())))
+ }),
kind if is_integral(kind) => Pointee::Integral,
_ => Pointee::Other,
}
@@ -415,19 +418,6 @@ fn is_teardown_name(name: &str) -> bool {
carries_word(name, &TEARDOWN_VERBS)
}
-fn record_behind_two_pointers(ty: &Type) -> Option<String> {
- let outer = ty.get_canonical_type();
- if outer.get_kind() != TypeKind::Pointer {
- return None;
- }
- let inner = outer.get_pointee_type()?.get_canonical_type();
- if inner.get_kind() != TypeKind::Pointer {
- return None;
- }
- let target = inner.get_pointee_type()?.get_canonical_type();
- (target.get_kind() == TypeKind::Record).then(|| record_name(&target))
-}
-
fn sole_handle_parameter(entity: &Entity) -> Option<String> {
let arguments = entity.get_arguments()?;
let [only] = arguments.as_slice() else {
@@ -477,9 +467,9 @@ fn collect_relations(entity: &Entity, target: &Path, into: &mut Vocabulary) {
// which was not malloc()-ed" with the frames inside the target library.
for argument in entity.get_arguments().unwrap_or_default() {
if let Some(ty) = argument.get_type()
- && let Some(record) = record_behind_two_pointers(&ty)
+ && let Some(record) = signature::record_behind_two_pointers(&shape_of(&ty))
{
- into.produced.insert(record);
+ into.produced.insert(record.to_owned());
}
}
if is_teardown_name(&name)
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/signature.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/signature.rs
index 64ee705a..0baf915c 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/signature.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-surface/src/signature.rs
@@ -111,7 +111,11 @@ pub enum Pointee {
Integral,
Record(String),
Function,
- Pointer,
+ // What the second indirection points AT, because the answer decides whether a double
+ // pointer is a slot the library fills or a buffer the caller must size, and collapsing
+ // it to a leaf made those two indistinguishable. `png_bytep *` and `struct
+ // archive_entry **` are the same shape here and opposite obligations one level down.
+ Pointer(Box<Pointee>),
Other,
}
@@ -186,6 +190,26 @@ pub fn handle_key(spelling: &str, shape: &Shape) -> Option<String> {
}
}
+// `X **out` where X is a record: the LIBRARY allocates the X and writes its address into a
+// slot the caller owns. That is the opposite obligation from `unsigned char **planes`, where
+// the caller allocates and the library reads - and the two are the same `Shape::Pointer` until
+// this asks what the second indirection points at. Canonical types only: `png_bytep *` spells
+// a record and is `unsigned char **`.
+#[must_use]
+pub fn record_behind_two_pointers(shape: &Shape) -> Option<&str> {
+ let Shape::Pointer {
+ pointee: Pointee::Pointer(inner),
+ ..
+ } = shape
+ else {
+ return None;
+ };
+ match inner.as_ref() {
+ Pointee::Record(name) => Some(name),
+ _ => None,
+ }
+}
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
pub enum ParamRole {
Buffer,
@@ -603,7 +627,7 @@ fn provisional_role(param: &Param) -> ParamRole {
Shape::Pointer { pointee, is_const } => match pointee {
Pointee::Function => ParamRole::Callback,
Pointee::Record(name) if STREAM_RECORDS.contains(&name.as_str()) => ParamRole::Stream,
- Pointee::Record(_) | Pointee::Pointer | Pointee::Other => ParamRole::Context,
+ Pointee::Record(_) | Pointee::Pointer(_) | Pointee::Other => ParamRole::Context,
byte if byte.is_byte_sized() => {
if matches!(pointee, Pointee::Char | Pointee::SignedChar)
&& name_has_token(param.name.as_ref(), PATH_NAMES)
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh
index 9bebdcbb..6cd07072 100755
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m3-gate.sh
@@ -526,6 +526,94 @@ else
fi
rm -rf "$WORK/upward"
+# B81. A double pointer is two opposite obligations wearing one shape. `unsigned char **planes`
+# is an array the CALLER allocates and the library reads, which is the B67 refusal and stays
+# refused. `struct filllib_entry **entry` is the reverse: the LIBRARY allocates the entry and
+# writes its address into a slot, so the harness owns nothing but the NULL local it passes the
+# address of. Canonical types are the only thing that separates them - libpng's `png_bytep *`
+# spells a record and IS `unsigned char **`.
+#
+# ONE tree carries both, differing in nothing but the inner pointee, which is what makes the
+# refusing assertion a control rather than a demonstration. Censused over all seven analysable
+# trees before the rule was written: 49 double-pointer parameters reach `bind` across ten
+# tree-runs and exactly 4 verdicts move, none of them into PLANS - so the accepting direction has
+# no real tree and is asserted here, exactly as B51(b)'s is.
+banner "M5 LIBRARY-FILLED OUT-PARAMS"
+
+FILLTREE="$WORK/filled/filllib"
+rm -rf "$WORK/filled"
+mkdir -p "$FILLTREE/include" "$FILLTREE/fuzz"
+cat >"$FILLTREE/include/filllib.h" <<'FILL_H'
+#include <stddef.h>
+
+struct filllib;
+struct filllib_entry;
+
+struct filllib *filllib_new(void);
+int filllib_open_memory(struct filllib *f, const void *buff, size_t size,
+ struct filllib_entry **first);
+int filllib_next_entry(struct filllib *f, struct filllib_entry **entry);
+int filllib_read_planes(struct filllib *f, unsigned char **planes);
+void filllib_free(struct filllib *f);
+FILL_H
+cat >"$FILLTREE/fuzz/filllib_fuzzer.c" <<'FILL_FUZZ'
+#include <stdint.h>
+
+#include "filllib.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ struct filllib *f = filllib_new();
+ struct filllib_entry *entry = NULL;
+ unsigned char *planes[3];
+
+ filllib_open_memory(f, data, size, &entry);
+ filllib_next_entry(f, &entry);
+ filllib_read_planes(f, planes);
+ filllib_free(f);
+ return 0;
+}
+FILL_FUZZ
+FILLPLAN="$OUT/filled-plan.txt"
+"$LISDEX" harness "$FILLTREE" --out "$OUT/filled-out" --plan-only --top 10 \
+ >"$FILLPLAN" 2>&1
+if grep -q 'extending \["filllib_next_entry"\]' "$FILLPLAN"; then
+ ok "a step whose out-param the library fills is copied into the climb"
+else
+ bad "the record out-param still stops the climb: $(cat "$FILLPLAN")"
+fi
+# The refusing direction, and the whole reason the rule asks about the INNER type. Same tree,
+# same handle, one call later - the only difference is that the caller must allocate this one.
+if ! grep 'extending' "$FILLPLAN" | grep -q 'filllib_read_planes'; then
+ ok "and a buffer the caller must size is still refused, so the climb stops there"
+else
+ bad "an out-param the caller must allocate was appended: $(grep extending "$FILLPLAN")"
+fi
+# The reach is from the CLIMB, not from the ranking: the step carries no corpus of its own, so
+# nothing but an extension can ever reach it.
+if grep -q 'PLANS filllib_next_entry' "$FILLPLAN"; then
+ bad "filllib_next_entry planned as an entry point, so the climb assertion proves nothing"
+else
+ ok "and the step cannot stand alone as an entry point, so only the climb reaches it"
+fi
+# The emitted C, because a plan that says AddressOf and a harness that compiles are different
+# claims. `--no-verify` cannot climb, so this reads the ENTRY POINT's own filled out-param.
+FILL_EMIT="$OUT/filled-emit"
+rm -rf "$FILL_EMIT"
+if "$LISDEX" harness "$FILLTREE" --out "$FILL_EMIT" --no-verify >/dev/null 2>&1 \
+ && FILL_C="$(find "$FILL_EMIT" -maxdepth 1 -name '*.c' | head -1)" && [ -n "$FILL_C" ]; then
+ if grep -qE 'struct filllib_entry \* ?lisdex_filled = NULL;' "$FILL_C" \
+ && grep -q 'filllib_open_memory(.*&lisdex_filled)' "$FILL_C"; then
+ ok "the harness declares the NULL local itself and passes its address, nothing more"
+ else
+ bad "the emitted C does not own the slot it hands over: \
+$(grep -n 'filllib_open_memory\|lisdex_filled' "$FILL_C" | head -3)"
+ fi
+else
+ bad "the library-filled tree emitted nothing to check for B81"
+fi
+rm -rf "$WORK/filled"
+
# The negative control the ladder must REFUSE to help: a tree with nothing to mine has no
# authored floor, so the ranking alone decides and no setup is invented.
BARE="$WORK/ladder-bare"
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh
index 3ae8c10a..40936812 100755
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/scripts/m4-gate.sh
@@ -41,11 +41,11 @@ fi
mkdir -p "$GATE"
-log "stage 1/12: build lisdex"
+log "stage 1/13: build lisdex"
cargo build -p lisdex
[ -x "$LISDEX_BIN" ] || die "lisdex binary not found at $LISDEX_BIN"
-log "stage 2/12: every oracle answers for itself"
+log "stage 2/13: every oracle answers for itself"
# The end-to-end controls below cannot isolate one coverage oracle from another: the stub
# and the unpopulated variant are each rejected by BOTH 3a and 3c, so either one alone
# keeps the gate green while the other is gutted. Each oracle owns unit tests that no
@@ -57,7 +57,7 @@ else
fail "the oracle crate's own tests do not pass - one of the four oracles is not doing its job"
fi
-log "stage 3/12: assemble the two corpora the oracles need"
+log "stage 3/13: assemble the two corpora the oracles need"
mkdir -p "$GATE"
rm -rf "$CORPUS" "$INVALID" "$CONTROLS"
mkdir -p "$CORPUS" "$INVALID" "$CONTROLS"
@@ -98,7 +98,7 @@ lisdex_verify() {
"$LISDEX_BIN" verify "$SRC" --include "$REPO" --work "$SCRATCH" "${FLAGS[@]}"
}
-log "stage 4/12: lisdex synthesizes AND self-verifies a harness with NO LLM"
+log "stage 4/13: lisdex synthesizes AND self-verifies a harness with NO LLM"
rm -rf "$SYNTH"
mapfile -d '' HARNESS_FLAGS < <(oracle_flags)
"$LISDEX_BIN" harness "$REPO" --out "$SYNTH" --top "$TOP" "${HARNESS_FLAGS[@]}" \
@@ -165,7 +165,7 @@ build_harness() {
)
}
-log "stage 5/12: independent cross-check - it compiles and every valid seed runs clean"
+log "stage 5/13: independent cross-check - it compiles and every valid seed runs clean"
if build_harness "$ENTRY" "$GATE/harness" afl 2>"$GATE/compile.log"; then
pass "synthesized harness compiles and links"
else
@@ -189,7 +189,7 @@ else
fail "$CRASHED/$SEEDS valid seeds crash or leak - the oracle would be unsound"
fi
-log "stage 6/12: the shipped judge ACCEPTS the harness it chose"
+log "stage 6/13: the shipped judge ACCEPTS the harness it chose"
if lisdex_verify "$ENTRY" "$GATE/verify-accepted" > "$GATE/verify-accepted.log" 2>&1; then
EDGES="$(grep -m1 -oE 'ACCEPTED.* - [0-9]+ edges' "$GATE/verify-accepted.log" \
| grep -oE '[0-9]+ edges' | grep -oE '^[0-9]+' || echo 0)"
@@ -203,7 +203,7 @@ else
fail "the shipped judge rejects the harness lisdex itself accepted"
fi
-log "stage 7/12: NEGATIVE CONTROL - a stub that ignores its input must be REJECTED"
+log "stage 7/13: NEGATIVE CONTROL - a stub that ignores its input must be REJECTED"
cat > "$CONTROLS/stub.c" <<'STUB'
// ©AngelaMos | 2026
// stub.c
@@ -231,7 +231,7 @@ else
fi
fi
-log "stage 8/12: NEGATIVE CONTROL - the unpopulated struct variant must be REJECTED"
+log "stage 8/13: NEGATIVE CONTROL - the unpopulated struct variant must be REJECTED"
VARIANTS="$(find "$SYNTH/candidates" -maxdepth 1 -name "$ENTRY_NAME.v*.c" | sort -V)"
VARIANT_COUNT="$(printf '%s\n' "$VARIANTS" | grep -c . || true)"
if [ "${VARIANT_COUNT:-0}" -lt 2 ]; then
@@ -246,7 +246,7 @@ else
fi
fi
-log "stage 9/12: NEGATIVE CONTROL - a harness that crashes on a valid seed must be REJECTED"
+log "stage 9/13: NEGATIVE CONTROL - a harness that crashes on a valid seed must be REJECTED"
cat > "$CONTROLS/crasher.c" <<'CRASHER'
// ©AngelaMos | 2026
// crasher.c
@@ -284,7 +284,7 @@ else
fi
fi
-log "stage 10/12: NEGATIVE CONTROL - a harness that leaks on a valid seed must be REJECTED"
+log "stage 10/13: NEGATIVE CONTROL - a harness that leaks on a valid seed must be REJECTED"
cat > "$CONTROLS/leaker.c" <<'LEAKER'
// ©AngelaMos | 2026
// leaker.c
@@ -321,7 +321,7 @@ else
fi
fi
-log "stage 11/12: lisdex drives a campaign against the SYNTHESIZED harness"
+log "stage 11/13: lisdex drives a campaign against the SYNTHESIZED harness"
rm -rf "$FINDINGS" "$DB"
"$LISDEX_BIN" fuzz \
--target "$GATE/harness" \
@@ -364,7 +364,7 @@ else
fail "crash is not an attributable magma canary trigger"
fi
-log "stage 12/12: oracle 3b judges an UPWARD extension, in both directions"
+log "stage 12/13: oracle 3b judges an UPWARD extension, in both directions"
# B51(b). Oracle 3b measures a candidate against the shorter call sequence it EXTENDS, so it
# needs a library whose author sequence continues past the entry point with a call this harness
# can copy. The census says no tree in the validation set has one - libpng's tail is
@@ -383,11 +383,13 @@ cat >"$LAB/lib/mylib.h" <<'LAB_H'
#include <stddef.h>
struct mylib;
+struct mylib_entry;
struct mylib *mylib_new(void);
int mylib_open_memory(struct mylib *m, const void *buff, size_t size);
int mylib_scan(struct mylib *m);
int mylib_touch(struct mylib *m);
+int mylib_next_entry(struct mylib *m, struct mylib_entry **entry);
void mylib_free(struct mylib *m);
LAB_H
cat >"$LAB/lib/mylib.c" <<'LAB_C'
@@ -395,11 +397,20 @@ cat >"$LAB/lib/mylib.c" <<'LAB_C'
#include "mylib.h"
+/* B81. The entry belongs to the LIBRARY and is freed with it, which is what
+ archive_read_next_header does - the harness owns only the slot it passes the address of. An
+ entry the caller had to free would be a LeakSanitizer report inside the target, and stage 10
+ proves this gate rejects those. */
+struct mylib_entry {
+ unsigned long tag;
+};
+
struct mylib {
const unsigned char *data;
size_t size;
size_t pos;
unsigned long acc;
+ struct mylib_entry entry;
};
/* Eight distinct blocks per switch, because the base harness has to clear oracle 3a's
@@ -408,6 +419,8 @@ struct mylib {
STEP(0) STEP(1) STEP(2) STEP(3) STEP(4) STEP(5) STEP(6) STEP(7)
#define EXTRA(n) static void extra##n(struct mylib *m) { m->acc ^= n * 11u + 3u; }
EXTRA(0) EXTRA(1) EXTRA(2) EXTRA(3) EXTRA(4) EXTRA(5) EXTRA(6) EXTRA(7)
+#define MARK(n) static void mark##n(struct mylib *m) { m->entry.tag += n * 13u + 5u; }
+MARK(0) MARK(1) MARK(2) MARK(3) MARK(4) MARK(5) MARK(6) MARK(7)
struct mylib *mylib_new(void) { return (struct mylib *)calloc(1, sizeof(struct mylib)); }
@@ -467,6 +480,30 @@ int mylib_touch(struct mylib *m)
return 0;
}
+/* The shape B81 unlocks: the library hands back a pointer to storage it owns. Its coverage has
+ to depend on the input or oracle 3b would reject it for the same reason it rejects
+ `mylib_touch`, which would make the acceptance below prove nothing about the out-param. */
+int mylib_next_entry(struct mylib *m, struct mylib_entry **entry)
+{
+ size_t i;
+
+ if (m == NULL || entry == NULL || m->data == NULL) { return -1; }
+ for (i = m->pos; i < m->size && i < 32; i++) {
+ switch ((m->data[i] >> 2) & 7u) {
+ case 0: mark0(m); break;
+ case 1: mark1(m); break;
+ case 2: mark2(m); break;
+ case 3: mark3(m); break;
+ case 4: mark4(m); break;
+ case 5: mark5(m); break;
+ case 6: mark6(m); break;
+ default: mark7(m); break;
+ }
+ }
+ *entry = &m->entry;
+ return 0;
+}
+
void mylib_free(struct mylib *m) { free(m); }
LAB_C
lab_target() {
@@ -489,6 +526,24 @@ LAB_FUZZ
}
lab_target scan
lab_target touch
+mkdir -p "$LAB/entry/include" "$LAB/entry/fuzz"
+cat >"$LAB/entry/fuzz/mylib_fuzzer.c" <<'LAB_ENTRY'
+#include <stdint.h>
+
+#include "mylib.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ struct mylib *m = mylib_new();
+ struct mylib_entry *entry = NULL;
+
+ mylib_open_memory(m, data, size);
+ mylib_next_entry(m, &entry);
+ mylib_free(m);
+ return 0;
+}
+LAB_ENTRY
+cp "$LAB/lib/mylib.h" "$LAB/entry/include/mylib.h"
python3 - "$LAB/seeds" <<'LAB_SEEDS'
import sys, os
target = sys.argv[1]
@@ -563,6 +618,38 @@ else
fail "the incomparable-map guard did not fire on a relinked LTO archive"
fi
+log "stage 13/13: a library-filled out-param compiles and runs against the real header"
+# B81. m3 asserts the PLAN says AddressOf and the emitted C declares the slot. Those are claims
+# about text. This is the claim text cannot make: the same library, a third tree, and the appended
+# `mylib_next_entry(ctx, &lisdex_filled)` has to type-check against the real header, link, and run
+# clean on every seed. Reaching oracle 3b at all is the proof, because 3b sits behind compilation,
+# execution and inter-seed divergence - a declaration that did not compile never gets here.
+#
+# The VERDICT is deliberately not asserted, and that is B80 rather than caution. Both outcomes
+# below mean the same thing about B81; which one appears is decided by whether this particular
+# relink renumbered the harness TU's own edges, and D33 measured that as unpredictable across two
+# trees over one library. Asserting acceptance would make this stage a coin flip on link order.
+# When B80 lands - the map holding only the library's fixed edges - this becomes an acceptance.
+lab_run entry
+if grep -qE 'extended by 1 author call\(s\): mylib_next_entry|appending mylib_next_entry' \
+ "$LAB/entry.log" && ! grep -q 'does not compile' "$LAB/entry.log"; then
+ pass "a step whose out-param the library fills compiles and runs against the real header"
+else
+ tail -6 "$LAB/entry.log" >&2
+ fail "the library-filled extension never reached the oracle that judges it"
+fi
+# The declaration is the harness's own, and LSAN is what proves the ownership line is drawn in
+# the right place: the entry belongs to the library, so nothing here frees it.
+ENTRY_C="$(find "$LAB/out-entry" -maxdepth 2 -name '*.c' | head -1)"
+if [ -n "$ENTRY_C" ] && grep -qE 'struct mylib_entry \* ?lisdex_filled = NULL;' "$ENTRY_C" \
+ && grep -q 'mylib_next_entry(ctx, &lisdex_filled);' "$ENTRY_C" \
+ && ! grep -q 'free(lisdex_filled)' "$ENTRY_C"; then
+ pass "the harness declares the slot, passes its address, and frees nothing it does not own"
+else
+ fail "the emitted extension does not own its slot: \
+$(grep -n 'lisdex_filled' "${ENTRY_C:-/dev/null}" | head -3)"
+fi
+
printf '\n'
if [ "$FAILURES" -eq 0 ]; then
printf '[m4] M4 EXIT GATE PASSED - the none tier synthesized and self-verified a harness with no LLM\n'