• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#import <Foundation/Foundation.h>
7#import <mach-o/dyld.h>
8
9#include <string>
10
11int main(int argc, char *argv[]) {
12  for (int i = 0; i < 10; i++) {
13    NSObjectFileImage im;
14
15	std::string path = std::string(argv[0]) + ".bundle";
16    NSObjectFileImageReturnCode rc =
17        NSCreateObjectFileImageFromFile(path.c_str(), &im);
18    if (rc != NSObjectFileImageSuccess) {
19      fprintf(stderr, "Could not load bundle.\n");
20      exit(-1);
21    }
22
23    NSModule handle = NSLinkModule(im, "a.bundle", 0);
24    if (handle == 0) {
25      fprintf(stderr, "Could not load bundle.\n");
26      exit(-1);
27    }
28    printf("h: %p\n", handle);
29  }
30
31  char *ptr = (char *)malloc(10);
32  ptr[10] = 'x';  // BOOM
33}
34
35// CHECK: AddressSanitizer: heap-buffer-overflow
36// CHECK: WRITE of size 1
37// CHECK: {{#0 .* in main}}
38// CHECK: is located 0 bytes to the right of 10-byte region
39