Programming · Testing
sanitizer-memory-debugging
/sanitizer-memory-debugging
Use when ASan/LSan reports nothing on a real target.
- Author
- Fantasy1220 ↗
- Repository
- code-audit-skills ↗
- Licence
- MIT
- Last repository change
- 29.10.2026
Assessment and security
96/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability21 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
- Files in this package
- 2
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
Deprecation
No signals detected. Repository changed on 29.10.2026, without references to retired models or APIs.
Licence
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when ASan/LSan reports nothing on a real target.
Original author description
Use when ASan/LSan reports nothing on a real target.
How it works
- When to use
- 1. The bug was optimised away (the 1 false negative)
- 2. Shared libraries: one runtime, -shared-libasan
- 3. LeakSanitizer semantics
- 4. Symbolisation without the target's symbols
- 5. Cross-compiling ASan for an embedded target
- Reading a report
- Verification checklist
- Output language
Original SKILL.md headings · 79 lines, 702 words
SKILL.md preview
--- name: sanitizer-memory-debugging description: "Use when ASan/LSan reports nothing on a real target." version: 1.0.0 license: MIT --- # Sanitizer Memory Debugging (ASan / LSan / UBSan) Static review finds suspects; sanitizers catch them **at the moment they happen**. This skill is the runtime half: build with ASan, get a stack, done. The interesting part isn't the happy path — it's the three places where a correct build still shows **nothing**, and you conclude "the sanitizer is broken" when in fact the evidence was optimised away or never symbolised. ## When to use - "ASan reports nothing but I know there's a leak" ← start at §1, this is the usual answer - Prove a suspected leak / overflow / use-after-free on hardware, not just on the host - Cross-compile the sanitizer runtime for an embedded target (RISC-V, ARM) - A library is `dlopen`ed and its leaks aren't attributed to it ## 1. The bug was optimised away (the #1 false negative) At `-O1`+ the compiler deletes a `malloc` whose result is **never read and never freed**. Not "the allocator is fine" — the call no longer exists. - Even a `volatile` read of **one byte** doesn't save it: the compiler can replace the whole `malloc` with a stack slot (observed with clang 22 on riscv64). - The pointer must **escape** to survive: store it in a `volatile` global, or hand it to an opaque function in another translation unit (no LTO). - The guaranteed fix is `-O0` for the code under test. > **Verify the bug survived before blaming the tool**: `objdump -d` the function and count the `malloc`/`memset` call sites. Zero means the demo was optimised out; two after rebuilding at `-O0` means it's live. ## 2. Shared libraries: one runtime, `-shared-libasan` When `main` dlopens or links a `.so` that contains the bug: - Build **both** with `-fsanitize=address -shared-libasan` so they share a single `libclang_rt.asan.so`. - Two statically-linked ASan runtimes produce *"ASan runtime does not come first"* and undefined behaviour. - The `.so`'s `malloc` is still intercepted, because the runtime sits earlier than libc in `DT_NEEDED`. In the report, frame #0 is the interceptor and frame #1 is the leak site inside the `.so`. ## 3. LeakSanitizer semantics - `ASAN_OPTIONS=detect_leaks=1` (default on Linux); leaks are reported at exit with a non-zero status. - LSan only calls **unreachable** allocations a leak. A pointer still held by a global or a live stack frame is "still reachable" and silent by default — that is often the real story. - Don't `dlclose` the leaking `.so` before exit, or the allocation stack can no longer be symbolised back to it. ## 4. Symbolisation without the target's symbols Embedded targets rarely ship `llvm-symbolizer` (and the cross toolchain's copy is host-arch, useless on-device). Reports then read `libleak.so+0xd10`. Resolve offline with the cross `addr2line`: ```bash <cross>-addr2line -e binary -f -C 0xd10 # function + file:line ``` Frame layout of a leak report: `#0` interceptor · `#1` your allocation site · callers · `__libc_start_main`. ## 5. Cross-compiling ASan for an embedded target ```bash clang --target=riscv64-unknown-linux-gnu --sysroot=<sysroot> \ -O0 -g -fsanitize=address -shared-libasan -fno-omit-frame-pointer \ [-fPIC -shared] -o out in.c ``` Two things bite here: the target needs a **compatible glibc** (ship one alongside and start the binary through its `ld-linux-*.so.1`), and GCC builds often lack `libsanitizer` entirely — if `-fsanitize=address` fails to link, that's the reason, and Clang is the way round it. Full recipe: `references/cross-compile-asan.md`. ## Reading a report | Line | Meaning | |---|---| | `ERROR: AddressSanitizer: heap-buffer-overflow` | "N bytes after M-byte region" + shadow bytes (`fa` = redzone, `00` = addressable) | | `ERROR: LeakSanitizer: detected memory leaks` | `Direct leak of N byte(s) in M object(s) allocated from:` + stack + `SUMMARY:` | | `SEGV on unknown address` | often a wild pointer from a truncated address or a freed object | ## Verification checklist 1. `objdump -d` confirms the buggy code survived the build. 2. `readelf -d` shows the exact `DT_NEEDED` closure — assemble the portable runtime from exactly that, nothing more. 3. Run with `ASAN_OPTIONS=detect_leaks=1`; expect a non-zero exit and a report. 4. Still silent? Go to §1 before anything else. ## Output language Report findings in the language the user writes to you in. Keep code, paths, flag names and sanitizer output verbatim — they are evidence, not prose.
Files in this package (2)
- SKILL.md 4 KB
- references/cross-compile-asan.md 3 KB
Versions
The database has no other skills named sanitizer-memory-debugging.
Database snapshot: 13.11.2026 · package version cc49226a90db (SHA-256 digest of the entire package)
Downloads in the last 30 days: 1 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100sanitizers
Compiler sanitizer skill for runtime bug detection in C/C++. Use when enabling and interpreting AddressSanitizer (ASan), UndefinedBehaviorSanitizer (UBSan), ThreadSanitizer (TSan), MemorySanitizer (MSan), or LeakSanitizer (LSan) with GCC or Clang. Activates on queries about… - 100sanitizers
Use when building, running, or interpreting ASan, UBSan, TSan, MSan, LSan, HWASan, or Miri for native or Rust code, including memory-corruption debugging, unsafe-code validation, and sanitizer CI wiring. Not for fuzz target setup: use fuzzing. - 95sanitizers
Use when building, running, or interpreting ASan, UBSan, TSan, MSan, LSan, HWASan, or Miri for native or Rust code, including memory-corruption debugging, unsafe-code validation, and sanitizer CI wiring. Not for fuzz target setup: use fuzzing. - 100address-sanitizer
Builds and runs code under AddressSanitizer to catch buffer overflows, use-after-free, and other memory errors during fuzzing or tests. Covers -fsanitize=address builds, ASAN_OPTIONS, reading the crash report, LeakSanitizer, and the overhead and platform trade-offs. Use when… - 95c-memory-errors
C语言内存/数组/指针错误的知识参考技能,涵盖数组越界(栈/堆/全局/字符串)、野指针、悬垂指针、空指针解引用、指针运算越界、malloc/free配套错误(double free/内存泄漏/分配大小算错)、sizeof数组退化、有符号整数溢出等未定义行为,以及错误现象对照、检测工具(ASAN/Valgrind)和安全编码守则。适用于嵌入式、单片机、硬件方向的C语言开发者和求职者。当用户询问"C语言数组越界/内存错误/野指针/段错误/堆破坏/未定义行为"的总结、排查、面试考点整理,或要求"把C内存错误总结做成可复制文档/练习/背诵版"时使用。 - 100rust-sanitizers-miri
Rust sanitizers and Miri skill for memory safety validation. Use when running AddressSanitizer or ThreadSanitizer on Rust code, interpreting sanitizer reports, using Miri to detect undefined behaviour in unsafe Rust, or validating unsafe code correctness. Activates on queries…