← all findings · FIND-0004 · samples/sample-c · S2 · accepted · filed 2026-09-16 14:48 UTC

FIND-201: handle_check bounds its copy only with a release-compiled-out assert

High8.2stack_writelibrary-api
Cluster FCL-77371ad9 (2 reports: FIND-0003) (duplicate of FIND-0003)
The RCF decoder's CHECK field is copied into a fixed 32-byte buffer inside the decode context and its length recorded. The only thing standing between the field length and the copy is assert(len <= sizeof(ctx->check)) (rcfg.c:197). In a release build — the configuration the audit guide mandates (-DNDEBUG) — that assert is compiled out, and memcpy(ctx->check, val, len) (rcfg.c:198) copies a caller-controlled length of up to the remaining stream bytes into the 32-byte check[] field of the on-stack rcfg_ctx. A stream of "RCF1" plus one CHECK field (type 0x09) whose length exceeds 32 overruns the buffer.
Act on it
Fix
Replace the assert with a real runtime bound: reject or clamp when `len > sizeof(ctx->check)` (return early, or copy `min(len, sizeof(ctx->check))` and record the clamped length) so the copy is bounded in every build configuration, not only when asserts are enabled.
Where
src/rcfg.c:handle_check:197 · reached through the library-api surface
Reproduce
sanitizer log sanitizer.txt (3 KB).
Confidence
reportable — source review placed the trigger within attacker_controls=bytes; 2 accept / 0 reject from independent reviewers; source-anchored trigger review voted Promote on 2 verified source anchors.
Affects
boundary rcfg_decode public API over an RCF stream (file bytes via rcfg_cli.c:59); attacker controls entire stream contents and length; needs the caller to supplies a byte buffer and its true length.

Fields

Field Value
Severity High8.2
Class stack-buffer-overflow
Primitive stack_write
Location src/rcfg.c:handle_check:197
Surface library-api
Boundary rcfg_decode public API over an RCF stream (file bytes via rcfg_cli.c:59)
Trigger source bytes
Caller controls entire stream contents and length
Caller contract unspecified
Trusted caller actions supplies a byte buffer and its true length
Parameter control direct
Reproducer carrier cli
Strategy S2— Invariant negation
Dedup key [loc] src/rcfg.c:197

Summary

The RCF decoder's CHECK field is copied into a fixed 32-byte buffer inside the decode context and its length recorded. The only thing standing between the field length and the copy is assert(len <= sizeof(ctx->check)) (rcfg.c:197). In a release build — the configuration the audit guide mandates (-DNDEBUG) — that assert is compiled out, and memcpy(ctx->check, val, len) (rcfg.c:198) copies a caller-controlled length of up to the remaining stream bytes into the 32-byte check[] field of the on-stack rcfg_ctx. A stream of "RCF1" plus one CHECK field (type 0x09) whose length exceeds 32 overruns the buffer.

Root Cause

rcfg_ctx ends with uint8_t check[RCFG_CHECK_CAP] where RCFG_CHECK_CAP is 32 (rcfg.c:22,41). handle_check asserts len <= sizeof(ctx->check) then does memcpy(ctx->check, val, len); ctx->check_len = len; (rcfg.c:197-199). len is the field length clamped only to the bytes remaining in the stream (rcfg.c:237,243-245), so it can be far larger than 32. The code relies on a runtime assert as its sole bounds enforcement. assert is a no-op under NDEBUG, so a release binary performs the copy unconditionally. The comment at rcfg.c:192-194 confirms the intent — "its length must fit the retained buffer" — but that invariant is only checked by the assert, which the shipping build removes.

In this audit's ASan build the assert is compiled in, so the reproducer aborts at the assert rather than in the memcpy; that abort is a debug artifact. The security defect is the release-build overflow the assert masks, hence a finding rather than a promoted crash.

Data Flow

The field length flows from the stream to a memcpy guarded only by an assert.

Source snippets referenced in Data Flow:

↳ Referenced in: read: rcfg_decode (src/rcfg.c:237) — field length flen read as big-endian u16 from stream bytes.

From src/rcfg.c (lines 235–239):

235     while (remaining >= RCFG_FIELD_HEADER) {
236       uint8_t  type = p[0];
237 ▶     uint16_t flen = read_be16(p + 1);
238       p += RCFG_FIELD_HEADER;
239       remaining -= RCFG_FIELD_HEADER;

↳ Referenced in: clamp: rcfg_decode (src/rcfg.c:243) — flen clamped only to remaining, permitting values > 32.

From src/rcfg.c (lines 241–245):

241       /* Clamp the value to what is actually present so a handler never walks off
242        * the end of the stream on the declared length alone. */
243 ▶     if (flen > remaining) {
244         flen = (uint16_t)remaining;
245       }

↳ Referenced in: dispatch: dispatch (src/rcfg.c:216) — routes a type 0x09 field to handle_check.

From src/rcfg.c (lines 214–218):

214       case RCFG_T_FLUSH: handle_flush(ctx); break;
215       case RCFG_T_OPT:   handle_opt(ctx, val, len); break;
216 ▶     case RCFG_T_CHECK: handle_check(ctx, val, len); break;
217       default:           break; /* unknown tag: skip */
218     }

↳ Referenced in: guard: handle_check (src/rcfg.c:197) — assert(len <= 32), removed under NDEBUG.

From src/rcfg.c (lines 195–199):

195   static void handle_check(rcfg_ctx *ctx, const uint8_t *val, uint16_t len)
196   {
197 ▶   assert(len <= sizeof(ctx->check));
198     memcpy(ctx->check, val, len);
199     ctx->check_len = len;

↳ Referenced in: overflow: handle_check (src/rcfg.c:198) — memcpy(ctx->check, val, len) writes past check[32] into the rest of the stack frame.

From src/rcfg.c (lines 196–200):

196   {
197     assert(len <= sizeof(ctx->check));
198 ▶   memcpy(ctx->check, val, len);
199     ctx->check_len = len;
200   }

Impact

In any release build (the guide's required -DNDEBUG posture), a producer of RCF stream bytes overwrites the tail of the on-stack rcfg_ctx and adjacent stack memory of rcfg_decode with caller-chosen bytes, up to roughly the remaining stream length. This is a stack-buffer-overflow with attacker-controlled content; in the ASan/assert build it manifests only as an assertion abort. The reproducer check_overflow.rcf (CHECK field, len 64) is included: it aborts at the assert here and would overflow in release.

Fix Direction

Replace the assert with a real runtime bound: reject or clamp when len > sizeof(ctx->check) (return early, or copy min(len, sizeof(ctx->check)) and record the clamped length) so the copy is bounded in every build configuration, not only when asserts are enabled.

Severity rationale

Severity is the CVSS v4.0 score — one industry-standard metric, computed by the vendored FIRST reference scorer. Base metrics come from the primitive and surface, with Attack Vector/Requirements also reflecting the trigger's caller-control facts (a trusted local API/call-sequence reads as AV:L/AT:P). The Threat metric (E) is read locally, not from threat intelligence: it grades how far this audit got toward proving the bug — a reproducer that fires is E:P, an unproven argument is E:U — so a demonstrated bug outranks a written one. FIRST defines E against public exploit availability, which is not what is measured here, and nothing in this run is publicly disclosed. Read E as reproduction confidence. The Environmental Security Requirements (CR/IR/AR) are left Not Defined — they model a deploying organisation's asset importance, which the scorer cannot derive, so a generic score keeps the CVSS-B worst case. Environmental modified impacts are set only to floor impact where reachability facts justify it (non-shipping surfaces, caller-only triggers). Cluster size remains a priority/verification fact because CVSS v4.0 has no cluster metric.

CVSS-BTE v4.0: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P/MAT:P → 8.2 (High) CVSS-B baseline: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N → 9.3 (Critical)

Metric Value Derived from
Attack Vector (AV) N surface tier = library
Attack Complexity (AC) L fixed — not separately modelled
Attack Requirements (AT) N intrinsic attack preconditions
Privileges Required (PR) N worst case — no auth signal
User Interaction (UI) N surface tier
Vuln Conf/Integ/Avail H/H/H primitive class = stack_write
Subseq Conf/Integ/Avail N/N/N primitive class
Threat Exploit Maturity (E) P local reproduction evidence — not public exploit availability
Env Requirements (CR/IR/AR) X/X/X not defined — deployer-set asset importance (CVSS-B baseline)
Env Modified AV/AC/AT/PR/UI X/X/P/X/X caller control / contract concern
Env Modified C/I/A impacts X/X/X/X/X/X non-shipping / caller-only reachability floor; demonstrated disclosure / availability

Severity level: High — CVSS bands: Critical ≥ 9.0, High ≥ 7.0, Medium ≥ 4.0, Low ≥ 0.1, None = 0.0.

Verification facts (not part of severity — triage priority): testcase + sanitizer log on disk.

Field derivation (each line is a reviewable claim):

  • surface=library → AV:N/UI:N
  • class=stack_write → VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
  • class preconditions → AT:N
  • PR:N (worst case — no auth signal), AC:L
  • reproducer/testcase artifact on disk → E:P
  • CR/IR/AR not defined — environmental requirements are a deployer concern (CVSS-B baseline)
  • caller controls limited trigger shape → MAT:P