问题
我试图创建缓冲区溢出,以了解有关Address Sanitizer的更多信息。我编写了以下代码,我认为这会导致缓冲区溢出,尽管我一定会误认为它没有引发期望的"Heap buffer overflow detected"
。
试图
var ints : [UInt8] = [ 1, 2, 3, 4 ]
let a = UnsafeMutableBufferPointer(start: &ints, count: ints.count)
a[28] = 17 // array out of index
通过单击我的应用程序>编辑方案...,然后单击“启用Address Sanitizer”,已启用Xcode中的Address Sanitizer。然后,我在运行之前重建了我的应用程序。
如何在Swift 2中创建缓冲区溢出?
来自https://developer.apple.com/videos/play/wwdc2015-413/?time=947
Address Sanitizer是基于C语言的LLVM工具。
和https://developer.apple.com/videos/play/wwdc2015-413/?time=1422
为了使用Address Sanitizer,Xcode将特殊标志传递给clang。
似乎Address Sanitizer仅可clang
用于C,Objective-C等,而不适用于Swift编译器swiftc
。
一个触发缓冲区溢出的简单C程序是
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
int *p = malloc(4 * sizeof(int));
p[28] = 17;
return 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句