feat(sast): C/C++ SAST for microcontroller firmware (#334) #339

Merged
sharang merged 1 commits from feat/c-cpp-sast into main 2026-09-23 13:07:50 +00:00
Owner

Closes #334. Part of the pilot P0 (#338).

Why

C/C++ trees got only semgrep --config=auto, which found nothing in firmware code, and no fixture had ever produced a C finding. A semgrep run that failed returned no findings, so the scan looked like clean code.

What

  • cppcheck (Debian bookworm package, added to the image and to tool-versions.json):
    • runs on C/C++ trees with -I for the project's inc/include directories, -j2 and a 900 s timeout;
    • the source list goes in through --file-list, so vendor code is left out without skipping a customer's own app/Drivers/;
    • XML v2 becomes findings with CWE, a relative file:line and a snippet;
    • a failure is recorded as the sast_c_cpp skipped stage.
  • CRA C rules in cra_semgrep.yaml, bound in the control map:
    • cra-ai-20: unbounded string functions, scanf("%s"), non-literal format strings (WARNING);
    • cra-ai-8: hard-coded credentials;
    • cra-ai-13: MD5, SHA-1 and DES (OpenSSL, mbedTLS, wolfSSL);
    • cra-ai-16: rand() used for keys, nonces and tokens;
    • cppcheck's memory-safety CWEs are bound under cra-ai-20.
  • Vendor code is left out of SAST: STM32Cube Drivers/ (only when it sits next to Core/), CMSIS, *_HAL_Driver, *_StdPeriph_Driver, third_party, vendor. The run records which directories as sast_vendor_code; the SBOM still covers them. A customer's own src/drivers/ and Zephyr's boards/vendor/ are kept.
  • semgrep:
    • --jobs 2;
    • a run with no report is now a recorded sast skipped stage;
    • paths are relative to the tree. The fingerprint uses that path, so existing findings on uploaded archives are created once more on their next scan;
    • snippets are read from the file, because open-source semgrep only returns requires login.

Verification

  • New nightly target fw-c-sensor-node: every planted flaw is found, and the strcpy in the vendored HAL is not:
    • cppcheck arrayIndexOutOfBounds, uninitvar, memleak;
    • all six CRA C rules.
  • The full local nightly (bless, then compare on a second fresh DB) passes. No other baseline changed, after the boards/vendor fix.
  • cargo fmt --check; clippy with the CI flags; compliance-agent lib tests (382) and control-map tests pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #334. Part of the pilot P0 (#338). ## Why C/C++ trees got only `semgrep --config=auto`, which found nothing in firmware code, and no fixture had ever produced a C finding. A semgrep run that failed returned no findings, so the scan looked like clean code. ## What - **cppcheck** (Debian bookworm package, added to the image and to `tool-versions.json`): - runs on C/C++ trees with `-I` for the project's `inc`/`include` directories, `-j2` and a 900 s timeout; - the source list goes in through `--file-list`, so vendor code is left out without skipping a customer's own `app/Drivers/`; - XML v2 becomes findings with CWE, a relative file:line and a snippet; - a failure is recorded as the `sast_c_cpp` skipped stage. - **CRA C rules** in `cra_semgrep.yaml`, bound in the control map: - `cra-ai-20`: unbounded string functions, `scanf("%s")`, non-literal format strings (WARNING); - `cra-ai-8`: hard-coded credentials; - `cra-ai-13`: MD5, SHA-1 and DES (OpenSSL, mbedTLS, wolfSSL); - `cra-ai-16`: `rand()` used for keys, nonces and tokens; - cppcheck's memory-safety CWEs are bound under `cra-ai-20`. - **Vendor code** is left out of SAST: STM32Cube `Drivers/` (only when it sits next to `Core/`), CMSIS, `*_HAL_Driver`, `*_StdPeriph_Driver`, `third_party`, `vendor`. The run records which directories as `sast_vendor_code`; the SBOM still covers them. A customer's own `src/drivers/` and Zephyr's `boards/vendor/` are kept. - **semgrep**: - `--jobs 2`; - a run with no report is now a recorded `sast` skipped stage; - paths are relative to the tree. The fingerprint uses that path, so existing findings on uploaded archives are created once more on their next scan; - snippets are read from the file, because open-source semgrep only returns `requires login`. ## Verification - New nightly target `fw-c-sensor-node`: every planted flaw is found, and the `strcpy` in the vendored HAL is not: - cppcheck `arrayIndexOutOfBounds`, `uninitvar`, `memleak`; - all six CRA C rules. - The full local nightly (bless, then compare on a second fresh DB) passes. No other baseline changed, after the `boards/vendor` fix. - `cargo fmt --check`; clippy with the CI flags; `compliance-agent` lib tests (382) and `control-map` tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-09-23 10:57:28 +00:00
feat(sast): C/C++ SAST for microcontroller firmware (#334)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 6m5s
fe53d0a447
C/C++ trees got only `semgrep --config=auto`, which returned nothing for
firmware code, and a failed semgrep run read as clean code.

- cppcheck (bookworm package) runs on C/C++ trees with the project's include
  directories, and its findings carry CWE, file:line and a snippet.
- Our own CRA C rules: unbounded string functions, scanf %s, non-literal
  format strings, hard-coded credentials, broken hashes/ciphers and rand()
  for keys and nonces, bound to cra-ai-8/13/16/20 in the control map, with
  cppcheck's memory-safety CWEs under cra-ai-20.
- Vendor SDK code (STM32Cube Drivers/, CMSIS, *_HAL_Driver, third_party) is
  left out of SAST and the run records which directories; the SBOM still
  covers it. A customer's own drivers/ and Zephyr's boards/vendor are kept.
- semgrep: --jobs 2; a run with no report becomes a recorded skipped stage;
  paths are relative to the tree, and snippets are read from the file
  (open-source semgrep only returns "requires login").
- Nightly fixture fw-c-sensor-node: every planted flaw is found, and the
  strcpy in the vendored HAL is not.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit fbf3a7cf29 into main 2026-09-23 13:07:50 +00:00
Sign in to join this conversation.