1 // Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=368.
3 // RUN: %clangxx_asan %s -Wno-deprecated-declarations -flat_namespace -bundle -undefined suppress -o %t.bundle
4 // RUN: %clangxx_asan %s -Wno-deprecated-declarations -o %t -framework Foundation && not %run %t 2>&1 | FileCheck %s
6 // NSCreateObjectFileImageFromFile/NSLinkModule isn't available on iOS
9 #import <Foundation/Foundation.h>
10 #import <mach-o/dyld.h>
14 int main(int argc, char *argv[]) {
15 for (int i = 0; i < 10; i++) {
18 std::string path = std::string(argv[0]) + ".bundle";
19 NSObjectFileImageReturnCode rc =
20 NSCreateObjectFileImageFromFile(path.c_str(), &im);
21 if (rc != NSObjectFileImageSuccess) {
22 fprintf(stderr, "Could not load bundle.\n");
26 NSModule handle = NSLinkModule(im, "a.bundle", 0);
28 fprintf(stderr, "Could not load bundle.\n");
31 printf("h: %p\n", handle);
34 char *ptr = (char *)malloc(10);
35 ptr[10] = 'x'; // BOOM
38 // CHECK: AddressSanitizer: heap-buffer-overflow
39 // CHECK: WRITE of size 1
40 // CHECK: {{#0 .* in main}}
41 // CHECK: is located 0 bytes after 10-byte region