42 lines · plain
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.bundle4// RUN: %clangxx_asan %s -Wno-deprecated-declarations -o %t -framework Foundation && not %run %t 2>&1 | FileCheck %s5 6// NSCreateObjectFileImageFromFile/NSLinkModule isn't available on iOS7// UNSUPPORTED: ios8 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, "Could not load bundle.\n");23 exit(-1);24 }25 26 NSModule handle = NSLinkModule(im, "a.bundle", 0);27 if (handle == 0) {28 fprintf(stderr, "Could not load bundle.\n");29 exit(-1);30 }31 printf("h: %p\n", handle);32 }33 34 char *ptr = (char *)malloc(10);35 ptr[10] = 'x'; // BOOM36}37 38// CHECK: AddressSanitizer: heap-buffer-overflow39// CHECK: WRITE of size 140// CHECK: {{#0 .* in main}}41// CHECK: is located 0 bytes after 10-byte region42