fix(sast): an upper-case format macro is not a non-literal format (#380) #395

Merged
sharang merged 1 commits from fix/format-macro into main 2026-09-25 11:27:23 +00:00
Owner

Closes #380. Stacked on #392, which is stacked on #391; it merges after them.

The C/C++ non-literal format-string rule fired on sprintf(buf, GET_REQUEST) when GET_REQUEST is a macro such as #define GET_REQUEST "GET / HTTP/1.1\r\n\r\n". Seen in anon767/STM32F7HTTPS. A macro like that expands to a literal, so it is a false positive.

Change

  • Rule cra-ai-20-c-non-literal-format-string: the format argument must now be neither a literal nor an upper-case macro name (^(?![A-Z][A-Z0-9_]*$)[^"]).
  • Still flagged: printf(user_fmt), printf(msg), snprintf(buf, 8, fmt_table[2]).
  • No longer flagged: sprintf(buf, GET_REQUEST), printf(LOG_FMT, msg).

Nightly

c-sensor-node/Core/Src/cli.cpp gets a std::printf(STATUS_FMT, state) call after its existing lines, so the baseline lines don't move. It must stay silent. semgrep over the fixture gives exactly the baseline's findings.

Checked

semgrep --validate on the rule pack; a before/after run on a sample with each case.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #380. Stacked on #392, which is stacked on #391; it merges after them. The C/C++ non-literal format-string rule fired on `sprintf(buf, GET_REQUEST)` when `GET_REQUEST` is a macro such as `#define GET_REQUEST "GET / HTTP/1.1\r\n\r\n"`. Seen in `anon767/STM32F7HTTPS`. A macro like that expands to a literal, so it is a false positive. ## Change - **Rule `cra-ai-20-c-non-literal-format-string`:** the format argument must now be neither a literal nor an upper-case macro name (`^(?![A-Z][A-Z0-9_]*$)[^"]`). - **Still flagged:** `printf(user_fmt)`, `printf(msg)`, `snprintf(buf, 8, fmt_table[2])`. - **No longer flagged:** `sprintf(buf, GET_REQUEST)`, `printf(LOG_FMT, msg)`. ## Nightly `c-sensor-node/Core/Src/cli.cpp` gets a `std::printf(STATUS_FMT, state)` call after its existing lines, so the baseline lines don't move. It must stay silent. semgrep over the fixture gives exactly the baseline's findings. ## Checked `semgrep --validate` on the rule pack; a before/after run on a sample with each case. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang changed target branch from feat/define-credentials to main 2026-09-25 11:16:40 +00:00
sharang added 1 commit 2026-09-25 11:16:40 +00:00
fix(sast): an upper-case format macro is not a non-literal format (#380)
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 9m20s
a9fa64314d
`sprintf(buf, GET_REQUEST)` with GET_REQUEST defined as a string literal
was reported as an externally controlled format string. Upper-case
macro names are now treated as constant formats; the nightly C++
fixture carries such a call, which must stay silent.

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