Code review cpp

From NoorQureshi/security-skills · View interactive version

Code review cpp is an AI agent skill from the GitHub repository NoorQureshi/security-skills. Security review of C / C++ code — memory-safety and the classic unsafe-API sinks. Load when reviewing C/C++ source/PR, on .c/.cc/.cpp/.h in scope, or "review this C code". Signals: Makefile/CMakeLists, strcpy/sprintf/memcpy, malloc/free, raw pointers, format strings, parsers.

How to use this skill

Skill file

C / C++ source review

When it applies

Reviewing native C/C++ (a service, a parser, a library). The bugs are overwhelmingly memory safety —

the highest-impact, most exploitable class — plus the handful of unsafe APIs that cause them.

Why it works

C/C++ has no bounds checking: a length mistake, a lifetime mistake, or attacker-controlled format

string becomes a memory-corruption primitive. Most of these trace to a small, greppable set of APIs

and patterns, and sanitizers/fuzzing confirm the ones static reading only suspects.

Sinks & patterns (grep, then reason about lengths and lifetimes)

an unchecked or attacker-influenced length; fixed stack buffers filled from input.

allocation or copy (malloc(n*size), len-1); signed/unsigned confusion in bounds checks.

pointers after realloc; C++ iterator invalidation, dangling references, std::move misuse.

untrusted data into objects, std::string↔C-string length mistakes.

Method

  1. Run clang --analyze/cppcheck and semgrep; treat as leads.
  2. rg 'strcpy|strcat|sprintf|gets|memcpy|system\(|printf\s*\([^"]' and, for each, trace the size and

the source of the data.

  1. For every allocation/copy, check the length's origin and arithmetic for overflow.
  2. Where reachable with input, confirm with a fuzzer + ASan (libFuzzer/AFL++) — a crash under ASan

is proof; escalate to exploit-memory-corruption for exploitability.

Gotchas

raw buffers and FFI boundaries are where they persist.

References

CERT C/C++ Coding Standard; OWASP C-Based Toolchain hardening; ASan/libFuzzer docs.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.