address-sanitizer
하는 일
버퍼 범위 밖 쓰기, 해제 후 사용 같은 메모리 실수를 보고하도록 코드를 빌드하는 방법을 보여 줍니다. 퍼징이나 단위 테스트 중 네이티브 코드를 테스트하는 개발자를 위한 것입니다.
사용하는 경우
- ✓C, C++, Rust 코드를 퍼징하면서 메모리 오류가 빨리 드러나기를 원할 때.
- ✓프로그램이 메모리 손상을 의심하게 충돌해서 더 분명한 보고가 필요할 때.
- ✓AddressSanitizer 보고서를 읽고 문제를 일으킨 줄을 찾아야 하는 경우.
스킬 링크
https://github.com/trailofbits/skills/blob/main/plugins/testing-handbook-skills/skills/address-sanitizer/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“단위 테스트를 실행할 때 메모리 오류가 보이도록, AddressSanitizer로 제 C 프로젝트를 빌드하고 싶어요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트는 메모리 연산에 검사를 넣는 컴파일러 플래그를 추가합니다. 프로그램이 메모리를 잘못 쓰면 도구가 멈추고, 오류가 난 위치를 보고서로 출력합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
AddressSanitizer (ASan)
AddressSanitizer (ASan) is a widely adopted memory error detection tool used extensively during software testing, particularly fuzzing. It helps detect memory corruption bugs that might otherwise go unnoticed, such as buffer overflows, use-after-free errors, and other memory safety violations.
Overview
ASan is a standard practice in fuzzing due to its effectiveness in identifying memory vulnerabilities. It instruments code at compile time to track memory allocations and accesses, detecting illegal operations at runtime.
Key Concepts
| Concept | Description |
|---|---|
| Instrumentation | ASan adds runtime checks to memory operations during compilation |
| Shadow Memory | Maps 20TB of virtual memory to track allocation state |
| Performance Cost | Approximately 2-4x slowdown compared to non-instrumented code |
| Detection Scope | Finds buffer overflows, use-after-free, double-free, and memory leaks |
When to Apply
Apply this technique when:
- Fuzzing C/C++ code for memory safety vulnerabilities
- Testing Rust code with unsafe blocks
- Debugging crashes related to memory corruption
- Running unit tests where memory errors are suspected
Skip this technique when:
- Running production code (ASan can reduce security)
- Platform is Windows or macOS (limited ASan support)
- Performance overhead is unacceptable for your use case
- Fuzzing pure safe languages without FFI (e.g., pure Go, pure Java)
Quick Reference
| Task | Command/Pattern |
|---|---|
| Enable ASan (Clang/GCC) | -fsanitize=address |
| Enable verbosity | ASAN_OPTIONS=verbosity=1 |
| Disable leak detection | ASAN_OPTIONS=detect_leaks=0 |
| Force abort on error | ASAN_OPTIONS=abort_on_error=1 |
| Multiple options | ASAN_OPTIONS=verbosity=1:abort_on_error=1 |
Step-by-Step
Step 1: Compile with ASan
Compile and link your code with the -fsanitize=address flag:
clang -fsanitize=address -g -o my_program my_program.c
The -g flag is recommended to get better stack traces when ASan detects errors.
Step 2: Configure ASan Options
Set the ASAN_OPTIONS environment variable to configure ASan behavior:
export ASAN_OPTIONS=verbosity=1:abort_on_error=1:detect_leaks=0
Step 3: Run Your Program
Execute the ASan-instrumented binary. When memory errors are detected, ASan will print detailed reports:
./my_program
Step 4: Adjust Fuzzer Memory Limits
ASan requires approximately 20TB of virtual memory. Disable fuzzer memory restrictions:
- libFuzzer:
-rss_limit_mb=0 - AFL++:
-m none
Common Patterns
Pattern: Basic ASan Integration
Use Case: Standard fuzzing setup with ASan
Before:
clang -o fuzz_target fuzz_target.c
./fuzz_target
After:
clang -fsanitize=address -g -o fuzz_target fuzz_target.c
ASAN_OPTIONS=verbosity=1:abort_on_error=1 ./fuzz_target
Pattern: ASan with Unit Tests
Use Case: Enable ASan for unit test suite
Before:
gcc -o test_suite test_suite.c -lcheck
./test_suite
After:
gcc -fsanitize=address -g -o test_suite test_suite.c -lcheck
ASAN_OPTIONS=detect_leaks=1 ./test_suite
Advanced Usage
Tips and Tricks
| Tip | Why It Helps |
|---|---|
Use -g flag |
Provides detailed stack traces for debugging |
Set verbosity=1 |
Confirms ASan is enabled before program starts |
| Disable leaks during fuzzing | Leak detection doesn't cause immediate crashes, clutters output |
Enable abort_on_error=1 |
Some fuzzers require abort() instead of _exit() |
Understanding ASan Reports
When ASan detects a memory error, it prints a detailed report including:
- Error type: Buffer overflow, use-after-free, etc.
- Stack trace: Where the error occurred
- Allocation/deallocation traces: Where memory was allocated/freed
- Memory map: Shadow memory state around the error
Example ASan report:
==12345==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60300000eff4 at pc 0x00000048e6a3
READ of size 4 at 0x60300000eff4 thread T0
#0 0x48e6a2 in main /path/to/file.c:42
Combining Sanitizers
ASan can be combined with other sanitizers for comprehensive detection:
clang -fsanitize=address,undefined -g -o fuzz_target fuzz_target.c
Platform-Specific Considerations
Linux: Full ASan support with best performance macOS: Limited support, some features
자주 묻는 질문
프로그램이 느려지나요?
네. 보통 약 2~4배 느려지므로 운영용이 아니라 테스트용입니다.
Windows에서도 되나요?
스킬에 따르면 Windows와 macOS에서는 지원이 제한적입니다.
운영 코드에서도 실행해야 하나요?
아니요. 보안을 낮출 수 있으므로 운영 코드에는 쓰지 말라고 설명합니다.
상세 정보
작성자의 원본 설명
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 fuzzing C/C++ or Rust that has unsafe blocks or FFI, when debugging a memory corruption crash, or when reading an ASan stack trace.
repo: trailofbits/skills
인기도
- GitHub 스타
- 8.0k
- 순위
- #12711
- 라이선스
- CC-BY-SA-4.0
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
audit-context-building
8.0k에이전트가 보안 검토 전에 낯선 코드베이스를 익히고, 각 함수가 가정하고 보장하며 의존하는 것을 정리하도록 돕습니다.
algorand-vulnerability-scanner
8.0k에이전트가 TEAL이나 PyTeal 기반 Algorand 스마트 계약에서 키 재설정 공격, 수수료 미검증 등 보안 문제 11가지를 찾도록 돕습니다.
audit-prep-assistant
8.0k에이전트가 외부 보안 검토를 위해 코드베이스를 준비하도록 돕습니다. 정적 분석, 테스트 커버리지, 죽은 코드 정리, 명확한 문서화를 포함합니다.
cairo-vulnerability-scanner
8.0k에이전트가 StarkNet Cairo 스마트 계약에서 오버플로, 위험한 계층 간 메시지, 서명 재사용 등 6가지 문제를 검사하도록 돕습니다.
비슷한 스킬
test-driven-development
311k에이전트가 기능이나 수정을 만들기 전에 실패하는 테스트를 먼저 쓰고, 그것을 통과시키는 가장 작은 코드를 작성하도록 가르칩니다.
verification-before-completion
311k에이전트가 작업, 수정, 빌드가 완료되었거나 통과했다고 말하기 전에 실제 점검을 실행하고 결과를 읽도록 가르칩니다.
migrate-to-shoehorn
310k테스트 파일의 위험한 타입 캐스팅을 shoehorn 라이브러리로 바꿔, 테스트가 일부 데이터만 써도 타입 검사를 통과하도록 돕습니다.