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

FIND-101: CHECK handler bounds an untrusted length with a debug assert only

High8.9stack_writelibrary-api
Cluster FCL-77371ad9 (2 reports: FIND-0004) (canonical)
The RCF decoder retains a "self-check" field for end-of-stream verification by copying its bytes into a fixed 32-byte buffer that lives inside the decoder's on-stack context. The only thing standing between the caller-controlled field length and that copy is assert(len <= sizeof(ctx->check)). The shortest reaching input is the 4-byte magic RCF1 followed by one field: type byte 0x09, a big-endian length above 32, and that many value bytes. In the asserts-on build this aborts; in a release build compiled with -DNDEBUG (the configuration this audit's own build guidance prescribes) the assert vanishes and memcpy(ctx->check, val, len) at rcfg.c:198 overruns the 32-byte ctx->check buffer by up to a few thousand caller-controlled bytes.
Act on it
Fix
Replace the `assert` at rcfg.c:197 with a runtime check that rejects or clamps an over-long CHECK field before the copy: e.g.
Where
src/rcfg.c:handle_check:197 · reached through the library-api surface
Reproduce
input input.rcf (107 B).
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 RCF stream bytes passed to rcfg_decode (file input via rcfg CLI); attacker controls full field bytes — type, length, and value contents; needs the caller to none beyond supplying the input stream.

Fields

Field Value
Severity High8.9
Class stack-buffer-overflow
Primitive stack_write
Location src/rcfg.c:handle_check:197
Surface library-api
Boundary RCF stream bytes passed to rcfg_decode (file input via rcfg CLI)
Trigger source bytes
Caller controls full field bytes — type, length, and value contents
Caller contract unspecified
Trusted caller actions none beyond supplying the input stream
Parameter control direct
Reproducer carrier cli
Strategy S2— Invariant negation
Dedup key [loc] src/rcfg.c:197

Summary

The RCF decoder retains a "self-check" field for end-of-stream verification by copying its bytes into a fixed 32-byte buffer that lives inside the decoder's on-stack context. The only thing standing between the caller-controlled field length and that copy is assert(len <= sizeof(ctx->check)). The shortest reaching input is the 4-byte magic RCF1 followed by one field: type byte 0x09, a big-endian length above 32, and that many value bytes. In the asserts-on build this aborts; in a release build compiled with -DNDEBUG (the configuration this audit's own build guidance prescribes) the assert vanishes and memcpy(ctx->check, val, len) at rcfg.c:198 overruns the 32-byte ctx->check buffer by up to a few thousand caller-controlled bytes.

Root Cause

handle_check stages the field into ctx->check, declared uint8_t check[RCFG_CHECK_CAP] with RCFG_CHECK_CAP == 32 (rcfg.c:22, 41). The comment at rcfg.c:192-194 states the length "must fit the retained buffer; a longer field indicates a corrupt stream and trips a debug invariant" — and the code enforces that invariant with nothing but assert(len <= sizeof(ctx->check)) (rcfg.c:197). assert is a debug-only construct: any release build defining NDEBUG expands it to a no-op, after which the immediately following memcpy(ctx->check, val, len) (rcfg.c:198) runs with no bound at all. len is the field's flen, taken directly from the on-wire big-endian u16 length and only clamped down to the bytes actually present in the stream (rcfg.c:237-245); a caller therefore chooses both the length (up to 65535, or up to remaining) and the overflowing bytes. Because ctx is a stack local in rcfg_decode and check is its last member, the overflow writes past the struct into adjacent stack frame state.

Data Flow

A file of bytes reaches the CHECK handler, whose only length guard is a debug assert.

Source snippets referenced in Data Flow:

↳ Referenced in: read: main (src/rcfg_cli.c:59) — reads the whole input file into a buffer and calls rcfg_decode over its exact length.

From src/rcfg_cli.c (lines 57–61):

57     }
58   
59 ▶   int fields = rcfg_decode(data, len);
60     free(data);
61   

↳ Referenced in: parse: rcfg_decode (src/rcfg.c:237) — reads the field's u16 length flen, clamps it only to remaining 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: dispatch: dispatch (src/rcfg.c:216) — routes type 0x09 to handle_check with val/len unchanged.

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 <= sizeof(ctx->check)), a no-op 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 up to len bytes into a 32-byte buffer inside the stack…

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

Any caller who can hand the decoder a stream — the documented, sole input boundary — overruns a 32-byte stack buffer with caller-controlled length and contents in any -DNDEBUG release build. This overwrites adjacent stack-frame state within rcfg_decode; with remaining bounded by the file size the overflow reaches into the thousands of bytes. In the asserts-on build observed here the same input reaches a reachable-assertion abort (CWE-617), a denial-of-service on the decoding process. Exploitability beyond memory corruption is unproven, but the stack smash with attacker-controlled contents is a classic control-flow-relevant primitive.

Fix Direction

Replace the assert at rcfg.c:197 with a runtime check that rejects or clamps an over-long CHECK field before the copy: e.g. if (len > sizeof(ctx->check)) return; (or clamp len to sizeof(ctx->check)), so validation of the untrusted length does not depend on assertions that release builds compile out.

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-BT 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 → 8.9 (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/X/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 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 input bytes → MAT:X