WWDC2015 Advanced Debugging and the address santinizer

打全局断点的时候 控制台不会输出exception
可以通过输入 po $arg1 来输出错误

What Is Address Sanitizer

Similar to Guard Malloc and Valgrind
Finds memory corruption at runtime
Less overhead
Integrated into Debug Navigator
Works on OS X, iOS(simulator and device)

Analyze Memory Corruption

Use after free
Heap buffer overflow
Stack buffer overflow
Global variable overflow
Overflows in C++ containers
Use after return

Compiler Optimization Level

None [00] is recommended
Fast [
01] is supported
Higher optimization is not supported

How Address Sanitizer Works

clang -fsanitize=address
At runtime, this binary links with as an runtime dylib that contains even more checks, and that dylib is required by the instrumentation

会进行一个检查

*p = 0xb00

--->

if (IsPoisoned(p)) Crash();
*p = 0xb00;

Shadow Mapping

IsPoisoned needs to be fast
1/8 of the address space
mmap'd at lunch

bool IsPosioned(Addr) {
  Shadow = Addr >> 3 + offset
  return (*Shadow) != 0
}

Heap

更改Malloc 的方式,从默认的连续分配内存改成间隔分配

Custom Malloc Implementation

Inserts poisoned "red zones" around allocations
Heap underflows/overflows
Delay reuse of freed memory
Use-after-free, double free
Collects stack traces for allocations and frees
Comprehensive error reports

Guard Malloc
NSZombie
Malloc SCribble
image.png
image.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,196评论 0 10
  • Redis 配置文件示例 注意:想要读取配置文件,Redis的第一个参数必须是文件的路径 ./redis-serv...
    起个名忒难阅读 5,057评论 0 1
  • This chapter discusses some of the design decisions that ...
    狂风无迹阅读 4,628评论 0 0
  • 2018年最后一个月已悄然而至,回想这一年好像并没有什么成就。考了几次的老师,终以两分之差而告终。挫败了信心,人也...
    文ww文阅读 1,846评论 0 3
  • 酒店的门突然开了,一阵冷风毫无顾忌地卷了进来,奕楠正百无聊赖地坐在酒店大堂的沙发上,被这突然袭来的冷风刺激了一...
    博赞教育张老师阅读 3,089评论 0 6

友情链接更多精彩内容