Address Sanitizer logo

Address Sanitizer

OrganizationPopular
trailofbits
address-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 fuzzing C/C++ or Rust that has unsafe blocks or FFI, when debugging a memory corruption crash, or when reading an ASan stack trace.

Overview

Publishertrailofbits
Repositoryskills
Skill nameaddress-sanitizer
Stars
7.1K
Forks
611
Bundled files
2
LicenseCC-BY-SA-4.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by trailofbits on GitHub. Read the source before you install it.

Installation

Install the Address Sanitizer AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/trailofbits/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/plugins/testing-handbook-skills/skills/address-sanitizer .claude/skills/address-sanitizer
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Address Sanitizer in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Address Sanitizer on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Address Sanitizer is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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

ConceptDescription
InstrumentationASan adds runtime checks to memory operations during compilation
Shadow MemoryMaps 20TB of virtual memory to track allocation state
Performance CostApproximately 2-4x slowdown compared to non-instrumented code
Detection ScopeFinds 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

TaskCommand/Pattern
Enable ASan (Clang/GCC)-fsanitize=address
Enable verbosityASAN_OPTIONS=verbosity=1
Disable leak detectionASAN_OPTIONS=detect_leaks=0
Force abort on errorASAN_OPTIONS=abort_on_error=1
Multiple optionsASAN_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:

bash
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:

bash
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:

bash
./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:

bash
clang -o fuzz_target fuzz_target.c
./fuzz_target

After:

bash
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:

bash
gcc -o test_suite test_suite.c -lcheck
./test_suite

After:

bash
gcc -fsanitize=address -g -o test_suite test_suite.c -lcheck
ASAN_OPTIONS=detect_leaks=1 ./test_suite

Advanced Usage

Tips and Tricks

TipWhy It Helps
Use -g flagProvides detailed stack traces for debugging
Set verbosity=1Confirms ASan is enabled before program starts
Disable leaks during fuzzingLeak detection doesn't cause immediate crashes, clutters output
Enable abort_on_error=1Some 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:

bash
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 may not work Windows: Experimental support, not recommended for production fuzzing

Anti-Patterns

Anti-PatternProblemCorrect Approach
Using ASan in productionCan make applications less secureUse ASan only for testing
Not disabling memory limitsFuzzer may kill process due to 20TB virtual memorySet -rss_limit_mb=0 or -m none
Ignoring leak reportsMemory leaks indicate resource management issuesReview leak reports at end of fuzzing campaign

Tool-Specific Guidance

libFuzzer

Compile with both fuzzer and address sanitizer:

bash
clang++ -fsanitize=fuzzer,address -g harness.cc -o fuzz

Run with unlimited RSS:

bash
./fuzz -rss_limit_mb=0

Integration tips:

  • Always combine -fsanitize=fuzzer with -fsanitize=address
  • Use -g for detailed stack traces in crash reports
  • Consider ASAN_OPTIONS=abort_on_error=1 for better crash handling

See: libFuzzer: AddressSanitizer

AFL++

Use the AFL_USE_ASAN environment variable:

bash
AFL_USE_ASAN=1 afl-clang-fast++ -g harness.cc -o fuzz

Run with unlimited memory:

bash
afl-fuzz -m none -i input_dir -o output_dir ./fuzz

Integration tips:

  • AFL_USE_ASAN=1 automatically adds proper compilation flags
  • Use -m none to disable AFL++'s memory limit
  • Consider AFL_MAP_SIZE for programs with large coverage maps

See: AFL++: AddressSanitizer

cargo-fuzz (Rust)

Use the --sanitizer=address flag:

bash
cargo fuzz run fuzz_target --sanitizer=address

Or configure in fuzz/Cargo.toml:

toml
[profile.release]
opt-level = 3
debug = true

Integration tips:

  • ASan is useful for fuzzing unsafe Rust code or FFI boundaries
  • Safe Rust code may not benefit as much (compiler already prevents many errors)
  • Focus on unsafe blocks, raw pointers, and C library bindings

See: cargo-fuzz: AddressSanitizer

honggfuzz

Compile with ASan and link with honggfuzz:

bash
honggfuzz -i input_dir -o output_dir -- ./fuzz_target_asan

Compile the target:

bash
hfuzz-clang -fsanitize=address -g target.c -o fuzz_target_asan

Integration tips:

  • honggfuzz works well with ASan out of the box
  • Use feedback-driven mode for better coverage with sanitizers
  • Monitor memory usage, as ASan increases memory footprint

Troubleshooting

IssueCauseSolution
Fuzzer kills process immediatelyMemory limit too low for ASan's 20TB virtual memoryUse -rss_limit_mb=0 (libFuzzer) or -m none (AFL++)
"ASan runtime not initialized"Wrong linking order or missing runtimeEnsure -fsanitize=address used in both compile and link
Leak reports clutter outputLeakSanitizer enabled by defaultSet ASAN_OPTIONS=detect_leaks=0
Poor performance (>4x slowdown)Debug mode or unoptimized buildCompile with -O2 or -O3 alongside -fsanitize=address
ASan not detecting obvious bugsBinary not instrumentedCheck with ASAN_OPTIONS=verbosity=1 that ASan prints startup info
False positivesInterceptor conflictsCheck ASan FAQ for known issues with specific libraries

Related Skills

Tools That Use This Technique

SkillHow It Applies
libfuzzerCompile with -fsanitize=fuzzer,address for integrated fuzzing with memory error detection
aflppUse AFL_USE_ASAN=1 environment variable during compilation
cargo-fuzzUse --sanitizer=address flag to enable ASan for Rust fuzz targets
honggfuzzCompile target with -fsanitize=address for ASan-instrumented fuzzing

Related Techniques

SkillRelationship
undefined-behavior-sanitizerOften used together with ASan for comprehensive bug detection (undefined behavior + memory errors)
fuzz-harness-writingHarnesses must be designed to handle ASan-detected crashes and avoid false positives
coverage-analysisCoverage-guided fuzzing helps trigger code paths where ASan can detect memory errors

Resources

Key External Resources

AddressSanitizer on Google Sanitizers Wiki

The official ASan documentation covers:

  • Algorithm and implementation details
  • Complete list of detected error types
  • Performance characteristics and overhead
  • Platform-specific behavior
  • Known limitations and incompatibilities

SanitizerCommonFlags

Common configuration flags shared across all sanitizers:

  • verbosity: Control diagnostic output level
  • log_path: Redirect sanitizer output to files
  • symbolize: Enable/disable symbol resolution in reports
  • external_symbolizer_path: Use custom symbolizer

AddressSanitizerFlags

ASan-specific configuration options:

  • detect_leaks: Control memory leak detection
  • abort_on_error: Call abort() vs _exit() on error
  • detect_stack_use_after_return: Detect stack use-after-return bugs
  • check_initialization_order: Find initialization order bugs

AddressSanitizer FAQ

Common pitfalls and solutions:

  • Linking order issues
  • Conflicts with other tools
  • Platform-specific problems
  • Performance tuning tips

Clang AddressSanitizer Documentation

Clang-specific guidance:

  • Compilation flags and options
  • Interaction with other Clang features
  • Supported platforms and architectures

GCC Instrumentation Options

GCC-specific ASan documentation:

  • GCC-specific flags and behavior
  • Differences from Clang implementation
  • Platform support in GCC

AddressSanitizer: A Fast Address Sanity Checker (USENIX Paper)

Original research paper with technical details:

  • Shadow memory algorithm
  • Virtual memory requirements (historically 16TB, now ~20TB)
  • Performance benchmarks
  • Design decisions and tradeoffs

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Address Sanitizer AI skill do?

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.

Why use Address Sanitizer on TypingMind?

Because you install it once and use it with any model. Address Sanitizer is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Address Sanitizer in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/trailofbits/skills/tree/main/plugins/testing-handbook-skills/skills/address-sanitizer. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Address Sanitizer?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Address Sanitizer?

As many as you like. As long as a model supports skills, you can use Address Sanitizer with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Address Sanitizer AI skill free?

Yes. It is published on GitHub by trailofbits under the CC-BY-SA-4.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇