securitymemory-safety
Memory Safety security skill
When & Why to Use This Skill
This Claude skill focuses on enhancing memory safety in C programming by identifying and mitigating critical vulnerabilities such as buffer overflows, use-after-free (UAF), and integer overflows. It provides developers with actionable patterns for secure memory management, hierarchical ownership via talloc, and the effective use of diagnostic tools like ASan and Valgrind to ensure robust and secure native code.
Use Cases
- Security-Focused Code Review: Automatically identifying 'red flag' patterns such as manual pointer arithmetic, unsafe memcpy usage, and missing bounds checks in C source code.
- Vulnerability Mitigation: Implementing hierarchical memory ownership and strict allocation validation to prevent memory leaks and UAF exploits.
- Integer Safety Auditing: Validating size_t multiplications and signed/unsigned conversions to prevent integer overflows during buffer size calculations.
- Diagnostic Tool Integration: Guiding the configuration and use of AddressSanitizer (ASan), UBSan, and Valgrind to detect undefined behavior and memory errors during the testing phase.
| name | security/memory-safety |
|---|---|
| description | Memory Safety security skill |
Memory Safety
C's primary vulnerability class. Buffer overflows, use-after-free, and integer issues remain the top attack vectors in native code.
ikigai Application
talloc mitigates but doesn't eliminate: Hierarchical ownership prevents leaks but not overflows or UAF within a context's lifetime.
Critical patterns:
- Bounds check ALL array access before use
- Validate sizes before allocation:
if (n > SIZE_MAX / elem_size) return ERR(...) - Never trust size values from external sources
- Use
talloc_array()not manual multiplication
Integer overflow risks:
size_tmultiplication for buffer sizes- Signed/unsigned conversion in comparisons
- Off-by-one in loop bounds
Detection tools:
- ASan (
make BUILD=sanitize) - buffer overflow, UAF - UBSan - undefined behavior, integer overflow
- Valgrind - memory errors, leaks
Review red flags: Manual pointer arithmetic, memcpy with computed sizes, array indexing without bounds check.