1// Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=368.
2
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
5
6// NSCreateObjectFileImageFromFile/NSLinkModule isn't available on iOS
7// UNSUPPORTED: ios
8
9#import <Foundation/Foundation.h>
10#import <mach-o/dyld.h>
11
12#include <string>
13
14int main(int argc, char *argv[]) {
15 for (int i = 0; i < 10; i++) {
16 NSObjectFileImage im;
17
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, format: "Could not load bundle.\n");
23 exit(status: -1);
24 }
25
26 NSModule handle = NSLinkModule(im, "a.bundle", 0);
27 if (handle == 0) {
28 fprintf(stderr, format: "Could not load bundle.\n");
29 exit(status: -1);
30 }
31 printf("h: %p\n", handle);
32 }
33
34 char *ptr = (char *)malloc(size: 10);
35 ptr[10] = 'x'; // BOOM
36}
37
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
42

source code of compiler-rt/test/asan/TestCases/Darwin/address-range-limit.mm