← all findings · FIND-0002 · samples/sample-c · S3 · accepted · filed 2026-09-16 14:36 UTC

FIND-001: CHECK field length validated only by a debug assert — stack overflow under NDEBUG

High8.1stack_writelibrary-api
Cluster FCL-217bf9c2 (3 reports: FIND-0005, FIND-0001) (duplicate of FIND-0005)
The RCF decoder's CHECK handler copies a self-check field into a 32-byte buffer inside the decode context after checking the length with a debug-only assert. In any release build compiled with -DNDEBUG — the configuration the project's own guidance prescribes for shipping — the assert is removed and a CHECK field longer than 32 bytes overflows the buffer. The shortest input is the 4-byte magic plus one CHECK field (type 0x09) whose declared length exceeds 32. The external party gets a caller-controlled stack overwrite. The bound at rcfg.c:197 is assert(len <= sizeof(ctx->check)); the copy at rcfg.c:198, memcpy(ctx->check, val, len), has no runtime guard.
Act on it
Fix
patch.diff is captured beside this report — Replace the debug assert with a runtime bound that holds in all builds: `if (len > sizeof(ctx->check)) return;` (or clamp `len` to `sizeof(ctx->check)` before the copy)..
Where
src/rcfg.c:handle_check:198 · reached through the library-api surface
Reproduce
no runnable reproducer — verify by reading the Data Flow against the source.
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 decoded by rcfg_decode (CLI file input, attacker_controls=bytes); attacker controls CHECK field length (big-endian u16) and value bytes; needs the caller to reads a file and calls rcfg_decode(data, len) once over the exact length.

Fields

Field Value
Severity High8.1
Class stack-buffer-overflow
Primitive stack_write
Location src/rcfg.c:handle_check:198
Surface library-api
Boundary RCF stream bytes decoded by rcfg_decode (CLI file input, attacker_controls=bytes)
Trigger source bytes
Caller controls CHECK field length (big-endian u16) and value bytes
Caller contract unspecified
Trusted caller actions reads a file and calls rcfg_decode(data, len) once over the exact length
Parameter control direct
Reproducer carrier cli
Strategy S3— Spec vs. implementation
Dedup key [loc] src/rcfg.c:198

Summary

The RCF decoder's CHECK handler copies a self-check field into a 32-byte buffer inside the decode context after checking the length with a debug-only assert. In any release build compiled with -DNDEBUG — the configuration the project's own guidance prescribes for shipping — the assert is removed and a CHECK field longer than 32 bytes overflows the buffer. The shortest input is the 4-byte magic plus one CHECK field (type 0x09) whose declared length exceeds

  1. The external party gets a caller-controlled stack overwrite. The bound at

rcfg.c:197 is assert(len <= sizeof(ctx->check)); the copy at rcfg.c:198, memcpy(ctx->check, val, len), has no runtime guard.

Root Cause

ctx->check is uint8_t check[RCFG_CHECK_CAP] with RCFG_CHECK_CAP == 32 (rcfg.c:22, rcfg.c:41), and it is the last member of rcfg_ctx, an object rcfg_decode allocates on its own stack frame (rcfg.c:228). handle_check validates the incoming length with assert(len <= sizeof(ctx->check)) (rcfg.c:197) and then unconditionally executes memcpy(ctx->check, val, len) (rcfg.c:198). assert expands to nothing when NDEBUG is defined, which is the standard release setting (and the setting the audit's own build guidance mandates for sanitizer trees). With the assert gone, len — a caller-controlled field length that rcfg_decode clamps only to the remaining stream bytes (rcfg.c:243-245), not to 32 — flows straight into the copy. A CHECK field with len up to the clamp writes past the 32-byte member into the rest of rcfg_ctx and then off the end of the decode frame. The assumed invariant ("its length must fit the retained buffer", rcfg.c:193) is enforced only in debug builds; the code has no production-path length check.

Data Flow

Caller-controlled file bytes set an oversized CHECK length that only a debug assert rejects.

Source snippets referenced in Data Flow:

↳ Referenced in: step: main (src/rcfg_cli.c:59) — hands the input buffer/length to rcfg_decode.

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

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

↳ Referenced in: step: rcfg_decode (src/rcfg.c:237-245) — reads big-endian u16 flen, clamps only to remaining.

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: step: dispatch (src/rcfg.c:216) — routes RCFG_T_CHECK (0x09) to handle_check with len=flen.

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: step: handle_check (src/rcfg.c:197) — assert(len <= 32) is the only bound; 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: step: handle_check (src/rcfg.c:198) — memcpy(ctx->check, val, len) writes len bytes into a 32-byte member of the on-stack ctx,…

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 release (NDEBUG) consumer decoding an untrusted RCF stream is exposed with a ~40-byte input (magic + 3-byte header + >32 value bytes). The overwrite is contiguous, caller-controlled in length and content, and lands over the tail of rcfg_ctx and adjacent stack. On the current sanitizer build (asserts enabled) the path aborts on the assert instead — an ABRT, not an ASan overflow — so this is filed as a source-proven defect rather than a promoted crash; the memory-safety violation manifests only once the assert is compiled out, which is the normal production build.

Fix Direction

Replace the debug assert with a runtime bound that holds in all builds: if (len > sizeof(ctx->check)) return; (or clamp len to sizeof(ctx->check) before the copy). An assert is diagnostic, not input validation, and must not be the sole guard on a copy whose length comes from untrusted input.

Patch

Captured patch — patch.diff (13 lines)

--- a/src/rcfg.c+++ b/src/rcfg.c@@ -194,7 +194,9 @@  * corrupt stream and trips a debug invariant. */ static void handle_check(rcfg_ctx *ctx, const uint8_t *val, uint16_t len) {-  assert(len <= sizeof(ctx->check));+  if (len > sizeof(ctx->check)) {+    return;+  }   memcpy(ctx->check, val, len);   ctx->check_len = len; }
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:U → 8.1 (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) U 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.

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
  • no reproducer artifact or positive reproduction → E:U
  • CR/IR/AR not defined — environmental requirements are a deployer concern (CVSS-B baseline)
  • caller controls input bytes → MAT:X