brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 62f4870 Raw
53 lines · cpp
1// RUN: %clangxx_asan -O0 %s -o %t2// RUN: not %run %t A 2>&1 | FileCheck --check-prefix=CHECK-A %s3// RUN: not %run %t B 2>&1 | FileCheck --check-prefix=CHECK-B %s4// RUN: not %run %t C 2>&1 | FileCheck --check-prefix=CHECK-C %s5// RUN: not %run %t D 2>&1 | FileCheck --check-prefix=CHECK-D %s6// RUN: not %run %t E 2>&1 | FileCheck --check-prefix=CHECK-E %s7 8// RUN: not %run %t K 2>&1 | FileCheck --check-prefix=CHECK-K %s9// RUN: not %run %t L 2>&1 | FileCheck --check-prefix=CHECK-L %s10// RUN: not %run %t M 2>&1 | FileCheck --check-prefix=CHECK-M %s11// RUN: not %run %t N 2>&1 | FileCheck --check-prefix=CHECK-N %s12// RUN: not %run %t O 2>&1 | FileCheck --check-prefix=CHECK-O %s13 14#include <sanitizer/asan_interface.h>15 16#include <stdlib.h>17#include <string.h>18int main(int argc, char **argv) {19  if (argc != 2) return 1;20  char *x = new char[16];21  memset(x, 0xab, 16);22  int res = 1;23  switch (argv[1][0]) {24    case 'A': res = __sanitizer_unaligned_load16(x + 15); break;25//  CHECK-A ERROR: AddressSanitizer: heap-buffer-overflow on address26//  CHECK-A: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-2]]27//  CHECK-A: is located 0 bytes after 16-byte region28    case 'B': res = __sanitizer_unaligned_load32(x + 14); break;29//  CHECK-B: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]30    case 'C': res = __sanitizer_unaligned_load32(x + 13); break;31//  CHECK-C: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]32    case 'D': res = __sanitizer_unaligned_load64(x + 15); break;33//  CHECK-D: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]34    case 'E': res = __sanitizer_unaligned_load64(x + 9); break;35//  CHECK-E: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]36 37    case 'K': __sanitizer_unaligned_store16(x + 15, 0); break;38//  CHECK-K ERROR: AddressSanitizer: heap-buffer-overflow on address39//  CHECK-K: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-2]]40//  CHECK-K: is located 0 bytes after 16-byte region41    case 'L': __sanitizer_unaligned_store32(x + 15, 0); break;42//  CHECK-L: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]43    case 'M': __sanitizer_unaligned_store32(x + 13, 0); break;44//  CHECK-M: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]45    case 'N': __sanitizer_unaligned_store64(x + 10, 0); break;46//  CHECK-N: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]47    case 'O': __sanitizer_unaligned_store64(x + 14, 0); break;48//  CHECK-O: main{{.*}}unaligned_loads_and_stores.cpp:[[@LINE-1]]49  }50  delete[] x;51  return res;52}53