问题
我正在尝试创建缓冲区溢出,以便了解有关 Address Sanitizer 的更多信息。我编写了以下代码,我认为会造成缓冲区溢出,但我一定是错误的,因为它没有抛出预期的“检测到堆缓冲区溢出”
。
尝试
var ints : [UInt8] = [ 1, 2, 3, 4 ]
let a = UnsafeMutableBufferPointer(start: &ints, count: ints.count)
a[28] = 17 // array out of index
我通过单击我的应用程序 > 编辑方案...,然后单击“启用地址 sanitizer ”,在 Xcode 中启用了地址 sanitizer 。然后我在运行之前重建了我的应用程序。
问题
如何在 Swift 2 中创建缓冲区溢出?
最佳答案
来自https://developer.apple.com/videos/play/wwdc2015-413/?time=947
Address Sanitizer is an LLVM tool for C-based languages.
和https://developer.apple.com/videos/play/wwdc2015-413/?time=1422
In order to use Address Sanitizer, Xcode passes a special flag to 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;
}
关于swift - 如何创建缓冲区溢出来测试 Address Sanitizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34485008/