mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-19 21:19: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
@@ -74,6 +74,14 @@ def classify_guard_text(text: str) -> str:
|
||||
# --- The specs the CPG queries are parameterised by ------------------------------------------------------
|
||||
|
||||
|
||||
# Buffer-overflow classes: the danger is a length, so a bound that dominates the sink discharges it. Only
|
||||
# CWE-121 is in the fact tables today, and it is C-only -- naming the family keeps a later fact from having
|
||||
# to remember this rule exists.
|
||||
OVERFLOW_CWES = frozenset(
|
||||
{"CWE-119", "CWE-120", "CWE-121", "CWE-122", "CWE-124", "CWE-126", "CWE-127", "CWE-787", "CWE-788", "CWE-805", "CWE-806"}
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TaintSpec:
|
||||
"""What a flow family's source-to-sink-minus-sanitizer query matches on, for one language.
|
||||
@@ -97,6 +105,12 @@ class TaintSpec:
|
||||
sources: tuple[str, ...]
|
||||
sinks: tuple[str, ...]
|
||||
sanitizers: tuple[str, ...]
|
||||
# Sinks whose danger is a LENGTH, and which a bound that dominates them therefore discharges. Derived
|
||||
# from the sink fact's own CWE rather than asserted here: CWE-121 is a stack buffer overflow, and a
|
||||
# `strcpy` a `len > 250` check governs is not the same claim as one nothing governs. A sanitizer list
|
||||
# cannot express this -- `strlen` appears in the guarded and unguarded case alike -- which is why the
|
||||
# discharge is a guard and not a call.
|
||||
bounded_sinks: tuple[str, ...] = ()
|
||||
safe_shape_sinks: tuple[str, ...] = ()
|
||||
|
||||
|
||||
@@ -210,11 +224,16 @@ def taint_specs(
|
||||
sanitizers = tuple(sorted({call for fact in scoped.sanitizers if not _is_shape(fact) for call in fact.calls}))
|
||||
safe_shapes = tuple(sorted({call for fact in scoped.sanitizers if _is_shape(fact) for call in fact.calls}))
|
||||
by_family: dict[str, set[str]] = {}
|
||||
bounded: dict[str, set[str]] = {}
|
||||
for sink in scoped.sinks:
|
||||
family = families.family_of_cwe(sink.cwe)
|
||||
if family is None:
|
||||
continue
|
||||
by_family.setdefault(family.id, set()).update(sink.calls)
|
||||
# A sink whose CWE is a buffer-overflow class is dischargeable by a bound that dominates it. The CWE
|
||||
# is on the fact already, so which sinks these are is read from the data rather than declared here.
|
||||
if sink.cwe in OVERFLOW_CWES:
|
||||
bounded.setdefault(family.id, set()).update(sink.calls)
|
||||
return {
|
||||
family_id: TaintSpec(
|
||||
family=family_id,
|
||||
@@ -222,6 +241,7 @@ def taint_specs(
|
||||
sources=sources,
|
||||
sinks=tuple(sorted(calls)),
|
||||
sanitizers=sanitizers,
|
||||
bounded_sinks=tuple(sorted(bounded.get(family_id, ()))),
|
||||
safe_shape_sinks=safe_shapes,
|
||||
)
|
||||
for family_id, calls in sorted(by_family.items())
|
||||
|
||||
Reference in New Issue
Block a user