1 | // Test that small memcpy works correctly. |
2 | |
3 | // RUN: %clangxx_asan %s -o %t |
4 | // RUN: not %run %t 8 24 2>&1 | FileCheck %s --check-prefix=CHECK |
5 | // RUN: not %run %t 16 32 2>&1 | FileCheck %s --check-prefix=CHECK |
6 | // RUN: not %run %t 24 40 2>&1 | FileCheck %s --check-prefix=CHECK |
7 | // RUN: not %run %t 32 48 2>&1 | FileCheck %s --check-prefix=CHECK |
8 | // RUN: not %run %t 40 56 2>&1 | FileCheck %s --check-prefix=CHECK |
9 | // RUN: not %run %t 48 64 2>&1 | FileCheck %s --check-prefix=CHECK |
10 | // REQUIRES: shadow-scale-3 |
11 | #include <assert.h> |
12 | #include <string.h> |
13 | #include <stdlib.h> |
14 | #include <stdio.h> |
15 | |
16 | #include <sanitizer/asan_interface.h> |
17 | |
18 | int main(int argc, char **argv) { |
19 | assert(argc == 3); |
20 | size_t poison_from = atoi(nptr: argv[1]); |
21 | size_t poison_to = atoi(nptr: argv[2]); |
22 | assert(poison_from <= poison_to); |
23 | char A1[64], A2[64]; |
24 | fprintf(stderr, format: "%zd %zd\n" , poison_from, poison_to - poison_from); |
25 | __asan_poison_memory_region(addr: &A1[0] + poison_from, size: poison_to - poison_from); |
26 | memcpy(dest: A1, src: A2, n: sizeof(A1)); |
27 | // CHECK: AddressSanitizer: use-after-poison |
28 | return 0; |
29 | } |
30 | |