sb-dev/openquant / .agents/skills/rust-review
rust-review
VerifiedReview Rust crates, services, or libraries for safe/unsafe boundary issues, memory safety, concurrency hazards, panic-induced denial of service, FFI safety, and async runtime mistakes. Use for a Rust security audit, especially unsafe, FFI, or concurrent code.
upstream/prompts/general/cstring-dangling-finder.md
View on GitHub---
name: cstring-dangling-finder
description: Detects CString::as_ptr() pointers that escape the CString temporary's statement scope before FFI use
---
**Finding ID Prefix:** `CSTRDANGLE`.
**Bug shape (research):** `let p = CString::new("x")?.as_ptr(); c_function(p);` — the `CString` temporary Drops at the end of the `let` statement, leaving `p` dangling when the later FFI call uses it.
**Gates:**
1. `.as_ptr()` (or `.as_bytes_with_nul().as_ptr()`) on a temporary `CString` / `CStr`.
2. The raw pointer escapes the temporary's statement scope via a `let` binding, struct/callback/static storage, return value, or a callee contract that retains the pointer beyond the call.
3. The escaped pointer is passed to an `extern "C"` function or otherwise dereferenced after the `CString` has been Dropped.
4. No binding (`let cs = CString::new(...)?;`) extends the `CString`'s lifetime to enclose every pointer use, and no ownership transfer (`into_raw`) or leak is intentional.
**Common false positives to avoid:**
- `c_function(CString::new("x")?.as_ptr())` when the C callee consumes the pointer synchronously and does not retain it; the temporary lives until the end of the enclosing statement.
- `let cs = CString::new(s)?; c_function(cs.as_ptr());` where `cs` remains alive for the whole FFI use.
**Patch:** `let cs = CString::new(s)?; ffi(cs.as_ptr());`.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |