Communitygithub.com

SamuelChien/mega-skills-collection

AddressSanitizerはファジング中のメモリエラーを検出します。C/C++コードのファジングでバッファオーバーフローやuse-after-freeバグを見つける際に使用します。

mega-skills-collection とは?

AddressSanitizer(ASan)は、ソフトウェアテスト、特にファジングにおいて広く採用されているメモリエラー検出ツールです。コンパイル時にコードを計測し、メモリアクセスを追跡することで、バッファオーバーフローやuse-after-freeなどのメモリ破壊バグを実行時に検出します。このスキルは、libFuzzer、AFL++、cargo-fuzz、honggfuzzなど主要なファザーへのASanの統合方法を網羅しています。ASanの有効化、オプション設定、メモリ制限の調整、エラーレポートの解釈といった実践的な手順を提供します。Linuxではフルサポート、macOSでは制限付き、Windowsでは実験的サポートと、プラットフォームごとの注意点も説明しています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/SamuelChien/mega-skills-collection/tree/HEAD/address-sanitizer

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

AddressSanitizer (ASan)

AddressSanitizer(ASan)は、ソフトウェアテスト、特にファジングで広く採用されているメモリエラー検出ツールです。バッファオーバーフロー、use-after-freeエラー、その他のメモリ安全性違反など、見過ごされがちなメモリ破壊バグを検出するのに役立ちます。

概要

ASanは、メモリの脆弱性を特定する効果の高さから、ファジングにおける標準的な手法です。コンパイル時にコードを計測してメモリの割り当てとアクセスを追跡し、実行時に不正な操作を検出します。

主要な概念

概念説明
計測 (Instrumentation)ASanはコンパイル中にメモリ操作に対するランタイムチェックを追加します
シャドウメモリ (Shadow Memory)20TBの仮想メモリをマッピングして割り当て状態を追跡します
パフォーマンスコスト非計測コードと比較して約2~4倍の速度低下
検出範囲バッファオーバーフロー、use-after-free、ダブルフリー、メモリリークを検出

適用タイミング

以下の場合にこの手法を適用します:

  • C/C++コードをメモリ安全性の脆弱性についてファジングする場合
  • unsafeブロックを含むRustコードをテストする場合
  • メモリ破壊に関連するクラッシュをデバッグする場合
  • メモリエラーが疑われるユニットテストを実行する場合

以下の場合はこの手法をスキップします:

  • 本番コードを実行する場合(ASanはセキュリティを低下させる可能性があります)
  • プラットフォームがWindowsまたはmacOSの場合(ASanのサポートが制限されています)
  • パフォーマンスオーバーヘッドが許容できない場合
  • FFIを使用しない純粋な安全言語(例:純粋なGo、純粋なJava)をファジングする場合

クイックリファレンス

タスクコマンド/パターン
ASanを有効にする (Clang/GCC)-fsanitize=address
冗長出力を有効にするASAN_OPTIONS=verbosity=1
リーク検出を無効にするASAN_OPTIONS=detect_leaks=0
エラー時に強制アボートASAN_OPTIONS=abort_on_error=1
複数のオプションASAN_OPTIONS=verbosity=1:abort_on_error=1

ステップバイステップ

ステップ1:ASanでコンパイルする

コードを-fsanitize=addressフラグでコンパイルおよびリンクします:

clang -fsanitize=address -g -o my_program my_program.c

-gフラグは推奨されます。ASanがエラーを検出したときにより良いスタックトレースを得るためです。

ステップ2:ASanオプションを設定する

ASAN_OPTIONS環境変数を設定してASanの動作を構成します:

export ASAN_OPTIONS=verbosity=1:abort_on_error=1:detect_leaks=0

ステップ3:プログラムを実行する

ASanで計測されたバイナリを実行します。メモリエラーが検出されると、ASanは詳細なレポートを出力します:

./my_program

ステップ4:ファザーのメモリ制限を調整する

ASanは約20TBの仮想メモリを必要とします。ファザーのメモリ制限を無効にします:

  • libFuzzer: -rss_limit_mb=0
  • AFL++: -m none

一般的なパターン

パターン:基本的なASan統合

使用例: 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

パターン:ASanとユニットテスト

使用例: ユニットテストスイートでASanを有効にする

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

高度な使用法

ヒントとコツ

ヒント役立つ理由
-gフラグを使用するデバッグ用の詳細なスタックトレースを提供します
verbosity=1を設定するプログラム起動前にASanが有効であることを確認します
ファジング中はリーク検出を無効にするリーク検出は即座のクラッシュを引き起こさず、出力を乱雑にします
abort_on_error=1を有効にする一部のファザーは_exit()の代わりにabort()を必要とします

ASanレポートの理解

ASanがメモリエラーを検出すると、詳細なレポートを出力します。これには以下が含まれます:

  • エラータイプ: バッファオーバーフロー、use-after-freeなど
  • スタックトレース: エラーが発生した場所
  • 割り当て/解放トレース: メモリが割り当てられ/解放された場所
  • メモリマップ: エラー周辺のシャドウメモリ状態

ASanレポートの例:

==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

サニタイザーの組み合わせ

ASanは他のサニタイザーと組み合わせて包括的な検出が可能です:

clang -fsanitize=address,undefined -g -o fuzz_target fuzz_target.c

プラットフォーム固有の考慮事項

Linux: ASanをフルサポート、最高のパフォーマンス macOS: サポートは限定的、一部の機能は動作しない可能性があります Windows: 実験的サポート、本番ファジングには推奨されません

アンチパターン

アンチパターン問題正しいアプローチ
本番環境でASanを使用するアプリケーションのセキュリティを低下させる可能性があるASanはテスト専用に使用する
メモリ制限を無効にしない20TBの仮想メモリによりファザーがプロセスを強制終了する可能性がある-rss_limit_mb=0または-m noneを設定する
リークレポートを無視するメモリリークはリソース管理の問題を示すファジングキャンペーンの終了時にリークレポートを確認する

ツール固有のガイダンス

libFuzzer

ファザーとアドレスサニタイザーの両方でコンパイルします:

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

無制限のRSSで実行します:

./fuzz -rss_limit_mb=0

統合のヒント:

  • -fsanitize=fuzzerと-fsanitize=addressを常に組み合わせてください
  • クラッシュレポートの詳細なスタックトレースには-gを使用します
  • より良いクラッシュ処理のためにASAN_OPTIONS=abort_on_error=1を検討してください

参照: libFuzzer: AddressSanitizer

AFL++

AFL_USE_ASAN環境変数を使用します:

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

無制限メモリで実行します:

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

統合のヒント:

  • AFL_USE_ASAN=1は適切なコンパイルフラグを自動的に追加します
  • AFL++のメモリ制限を無効にするには-m noneを使用します
  • カバレッジマップが大きいプログラムにはAFL_MAP_SIZEを検討してください

参照: AFL++: AddressSanitizer

cargo-fuzz (Rust)

--sanitizer=addressフラグを使用します:

cargo fuzz run fuzz_target --sanitizer=address

または、fuzz/Cargo.tomlで設定します:

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

統合のヒント:

  • ASanはunsafeなRustコードやFFI境界のファジングに役立ちます
  • 安全なRustコードはそれほど恩恵を受けない可能性があります(コンパイラが既に多くのエラーを防ぎます)
  • unsafeブロック、生ポインタ、Cライブラリのバインディングに焦点を当ててください

参照: cargo-fuzz: AddressSanitizer

honggfuzz

ASanでコンパイルし、honggfuzzとリンクします:

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

ターゲットをコンパイルします:

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

統合のヒント:

  • honggfuzzはASanとそのまま動作します
  • サニタイザーと併用する場合、カバレッジ駆動モードを使用してより良いカバレッジを得てください
  • ASanはメモリフットプリントを増加させるため、メモリ使用量を監視してください

トラブルシューティング

問題原因解決策
ファザーが即座にプロセスを強制終了するASanの20TB仮想メモリに対してメモリ制限が低すぎる-rss_limit_mb=0(libFuzzer)または-m none(AFL++)を使用する

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

SamuelChien/mega-skills-collection

Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

SamuelChien/mega-skills-collection

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

SamuelChien/mega-skills-collection

Ingeniero de Sistemas de Andru.ia. Diseña, redacta y despliega nuevas habilidades (skills) dentro del repositorio siguiendo el Estándar de Diamante.

SamuelChien/mega-skills-collection

Estratega de Inteligencia de Dominio de Andru.ia. Analiza el nicho específico de un proyecto para inyectar conocimientos, regulaciones y estándares únicos del sector. Actívalo tras definir el nicho.

SamuelChien/mega-skills-collection

2D game development principles. Sprites, tilemaps, physics, camera.

SamuelChien/mega-skills-collection

3D game development principles. Rendering, shaders, physics, cameras.

SamuelChien/mega-skills-collection

Expert in building 3D experiences for the web - Three.js, React Three Fiber, Spline, WebGL, and interactive 3D scenes. Covers product configurators, 3D portfolios, immersive websites, and bringing depth to web experiences.

SamuelChien/mega-skills-collection

Accessibility audit skill for scanning, fixing, and verifying WCAG 2.2 Level A and AA compliance across React, Next.js, Vue, Angular, Svelte, and plain HTML codebases. Use when auditing accessibility, fixing a11y violations, checking color contrast, generating compliance reports, or integrating accessibility checks into CI/CD pipelines.

SamuelChien/mega-skills-collection

Ab Test Analyzer - Auto-activating skill for Data Analytics. Triggers on: ab test analyzer, ab test analyzer Part of the Data Analytics skill category.

SamuelChien/mega-skills-collection

A B Test Config Creator - Auto-activating skill for ML Deployment. Triggers on: a b test config creator, a b test config creator Part of the ML Deployment skill category.

SamuelChien/mega-skills-collection

When the user wants to plan, design, or implement an A/B test or experiment. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "conversion experiment," "statistical significance," or "test this." For tracking implementation, see analytics-tracking.

SamuelChien/mega-skills-collection

Acceptance Criteria Creator - Auto-activating skill for Enterprise Workflows. Triggers on: acceptance criteria creator, acceptance criteria creator Part of the Enterprise Workflows skill category.

SamuelChien/mega-skills-collection

Use when a coding task should be driven end-to-end from issue intake through implementation, review, deployment, and acceptance verification with minimal human re-intervention.

SamuelChien/mega-skills-collection

Accessibility Audit Runner - Auto-activating skill for Frontend Development. Triggers on: accessibility audit runner, accessibility audit runner Part of the Frontend Development skill category.

SamuelChien/mega-skills-collection

You are an accessibility expert specializing in WCAG compliance, inclusive design, and assistive technology compatibility. Conduct audits, identify barriers, and provide remediation guidance.

SamuelChien/mega-skills-collection

Web accessibility patterns for WCAG 2.2 compliance including ARIA, keyboard navigation, screen readers, and testing

SamuelChien/mega-skills-collection

Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed, or change policy for the Discord channel.

SamuelChien/mega-skills-collection

Create unified specification packages across Business, Development, and Design teams. Staged elaboration (L0 Vision → L1 Requirements → L2 Team Detail → L3 Acceptance Criteria) to build shared understanding. Does not write code.

SamuelChien/mega-skills-collection

Research a company or person and get actionable sales intel. Works standalone with web search, supercharged when you connect enrichment tools or your CRM. Trigger with "research [company]", "look up [person]", "intel on [prospect]", "who is [name] at [company]", or "tell me about [company]".

SamuelChien/mega-skills-collection

Validate messaging consistency across website, GitHub repos, and local documentation generating read-only discrepancy reports. Use when checking content alignment or finding mixed messaging. Trigger with phrases like "check consistency", "validate documentation", or "audit messaging".

関連スキル