mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-20 05:29:28 +00:00
feat(model): a bound on the data lowers the rung, it does not clear it
contributor-scan 2.12. c/injection and c/memory carried zero sanitizers, so no C flow could ever be discharged: every `argv -> strcpy` entailed however carefully it was bounded. Which sinks can be discharged this way is read from the sink fact's own CWE rather than declared: CWE-121 is a stack buffer overflow, so gets/sprintf/strcat/strcpy qualify. It is the only overflow CWE in the fact tables and it is C-only, so no Python or JavaScript sink is touched and the pair corpus is unaffected -- gates byte-identical. Not a sanitizer list, because `strlen` appears in the guarded and the unguarded case alike; the discharge is a guard, not a call. **The first implementation required the bound to DOMINATE the sink, and it found nothing.** libpng guards `strcpy(outname+len, ".png")` with `(len = strlen(inname)) > 250`, but that check sits on an else-if chain whose sibling branch skips it entirely, and the protection reaches the sink through an `error` flag: `++error` in the guarded branch, `if (!error)` around the copy. Joern's dominator set for that sink has 89 calls and correctly excludes the bound; `controlledBy` returns none either. Verified against the CPG before the rule was changed rather than after it failed. So the bound is searched in the method, and the consequence is corroborated rather than silence. That is the honest rung: a bound on this variable means the graph has NOT shown the copy is unguarded, and it has not shown it is guarded either -- off-by-one being how bounds fail. The judge is asked. Proving the flag-mediated case needs path-sensitive reasoning this arbiter does not do. libpng entailed 3 -> 1 The survivor is also a false positive: `strcpy(output + len, ".icc")` in iccfrompng.c, where `output = malloc(len + 5)` makes it fit exactly. That is a different discharge shape -- allocated to size, not bounds-checked -- and it is recorded as 2.13 rather than chased. Both shapes were found on one repository, and extending a rule until that repository is clean is the overfitting Req 8 exists to prevent; 2.13 requires a second C checkout with a genuine CWE-121 so the change can be measured for what it silences as well as what it clears. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01T7XD7x5KonMdmGRkp63EQG
This commit is contained in:
co-authored by
Claude Opus 5
parent
6dc25d77e4
commit
9221ba8e40
@@ -40,6 +40,7 @@ def request_params(
|
||||
"file": file,
|
||||
"parameterSources": "true" if parameter_sources else "false",
|
||||
"callDepth": str(call_depth),
|
||||
"boundedSinks": spec.bounded_sinks,
|
||||
}
|
||||
|
||||
|
||||
@@ -76,10 +77,18 @@ def verdict(
|
||||
# still vulnerable on the strength of a flow that names no attacker input.
|
||||
modelled = [flow for flow in flows if _from_modelled_source(flow, spec)]
|
||||
considered = modelled or flows
|
||||
unsanitized = [flow for flow in considered if not flow["sanitized"]]
|
||||
# A flow the graph cannot see a discharge for is the finding; a sanitized or BOUNDED one is a question.
|
||||
# libpng bounds `strcpy(outname+len, ".png")` with `(len = strlen(inname)) > 250` against a char[256],
|
||||
# and entailing it is a claim the code contradicts. But the bound reaches the sink through an `error`
|
||||
# flag rather than by dominating it, so the graph has not shown the copy is guarded either -- and a
|
||||
# bound is no proof of safety in any case, off-by-one being the classic way they fail. Corroborated is
|
||||
# the honest rung: the model cannot assert this, so the judge is asked instead of the site being
|
||||
# silenced.
|
||||
open_flows = [flow for flow in considered if not flow["sanitized"] and not flow["bounded"]]
|
||||
# Deterministic by construction: a total order, then take the first. Nothing depends on engine ordering.
|
||||
chosen = min(unsanitized or considered, key=lambda flow: _rank(flow, spec))
|
||||
rung = Rung.ENTAILED if not chosen["sanitized"] else Rung.CORROBORATED
|
||||
chosen = min(open_flows or considered, key=lambda flow: _rank(flow, spec))
|
||||
settled = bool(chosen["sanitized"]) or bool(chosen["bounded"])
|
||||
rung = Rung.CORROBORATED if settled else Rung.ENTAILED
|
||||
return Verdict(rung=rung, family=spec.family, witness=_witness(chosen), location=_location(chosen))
|
||||
|
||||
|
||||
@@ -102,6 +111,8 @@ def _flows(rows: object, *, function: str) -> list[dict[str, object]]:
|
||||
"sinkLine": str(row.get("sinkLine", "")),
|
||||
"sinkMethod": str(row.get("sinkMethod", "")),
|
||||
"sinkFile": str(row.get("sinkFile", "")),
|
||||
"bounded": bool(row.get("bounded", False)),
|
||||
"bound": str(row.get("bound", "")),
|
||||
"source": str(row.get("source", "")),
|
||||
"sanitized": bool(row.get("sanitized", False)),
|
||||
"length": _as_int(row.get("length")),
|
||||
@@ -172,7 +183,9 @@ def _witness(flow: Mapping[str, object]) -> str:
|
||||
line = flow.get("sinkLine") or "?"
|
||||
where = str(flow.get("sinkFile") or "")
|
||||
at = f" in {where}" if where else ""
|
||||
return f"{flow['source']} -> {flow['sink']}{at} (line {line}, {flow['length']} steps)"
|
||||
bound = str(flow.get("bound") or "")
|
||||
governed = f", governed by `{bound}`" if flow.get("bounded") and bound else ""
|
||||
return f"{flow['source']} -> {flow['sink']}{at} (line {line}, {flow['length']} steps{governed})"
|
||||
|
||||
|
||||
def _location(flow: Mapping[str, object]) -> str:
|
||||
|
||||
Reference in New Issue
Block a user