AD5023: EnableUBSanMachO¶
Summary¶
| Property | Value |
|---|---|
| ID | AD5023 |
| Name | EnableUBSanMachO |
| Category | Security |
| Severity | Note |
| Applies to | Mach-O (macOS, iOS) |
Description¶
Mach-O binaries used for testing should consider enabling UndefinedBehaviorSanitizer (UBSAN) to detect undefined behavior.
Note: This is an informational rule. UBSAN is for development and testing.
How It Works¶
The rule checks for UBSAN symbols:
__ubsan_handle_*functions- UBSAN runtime library
- Type sanitizer metadata
Why This Matters¶
Undefined behavior can lead to security vulnerabilities. UBSAN catches these issues during development.
What UBSAN Detects¶
| Issue | Detection |
|---|---|
| Signed overflow | ✓ |
| Division by zero | ✓ |
| Null dereference | ✓ |
| Invalid shifts | ✓ |
| Out-of-bounds access | ✓ |
| Type mismatches | ✓ |
Xcode Integration¶
UBSAN is built into Xcode and easy to enable:
- Select scheme → Edit Scheme
- Run → Diagnostics
- Enable "Undefined Behavior Sanitizer"
Command Line Usage¶
# Clang
clang -fsanitize=undefined -g program.c
# Specific checks
clang -fsanitize=signed-integer-overflow,null -g program.c
Performance¶
| Mode | Overhead |
|---|---|
| Full UBSAN | 10-100% |
| Production | Not recommended |
Resolution¶
Enable UBSAN in Xcode or via command line:
# Xcode project setting
CLANG_UNDEFINED_BEHAVIOR_SANITIZER = YES
# CMake
add_compile_options(-fsanitize=undefined)
add_link_options(-fsanitize=undefined)