|
7 | 7 | // RUN: %env_asan_opts=detect_container_overflow=0 %run %t crash |
8 | 8 | // |
9 | 9 | // Test crash due to __sanitizer_annotate_contiguous_container. |
| 10 | +// |
| 11 | +// Test with -D__ASAN_DISABLE_CONTAINER_OVERFLOW__ flag - should not crash |
| 12 | +// RUN: %clangxx_asan -D__ASAN_DISABLE_CONTAINER_OVERFLOW__ -O %s -o %t-no-overflow |
| 13 | +// RUN: %run %t-no-overflow crash |
| 14 | +// RUN: %run %t-no-overflow bad-bounds |
| 15 | +// RUN: %run %t-no-overflow unaligned-bad-bounds |
| 16 | +// RUN: %run %t-no-overflow odd-alignment |
| 17 | +// RUN: %run %t-no-overflow odd-alignment-end |
| 18 | +// |
| 19 | +// Test overflow checks can be disabled |
10 | 20 |
|
11 | 21 | #include <assert.h> |
12 | 22 | #include <string.h> |
13 | 23 |
|
14 | | -extern "C" { |
15 | | -void __sanitizer_annotate_contiguous_container(const void *beg, const void *end, |
16 | | - const void *old_mid, |
17 | | - const void *new_mid); |
18 | | -} // extern "C" |
| 24 | +// public definition of __sanitizer_annotate_contiguous_container |
| 25 | +#include "sanitizer/common_interface_defs.h" |
19 | 26 |
|
20 | 27 | static volatile int one = 1; |
21 | 28 |
|
22 | 29 | int TestCrash() { |
23 | 30 | long t[100]; |
24 | 31 | t[60] = 0; |
| 32 | +#if __has_feature(address_sanitizer) && !__ASAN_DISABLE_CONTAINER_OVERFLOW__ |
25 | 33 | __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100, |
26 | 34 | &t[0] + 50); |
27 | | -// CHECK-CRASH: AddressSanitizer: container-overflow |
28 | | -// CHECK-CRASH: if you don't care about these errors you may set ASAN_OPTIONS=detect_container_overflow=0 |
29 | | - return (int)t[60 * one]; // Touches the poisoned memory. |
| 35 | +#endif |
| 36 | + // CHECK-CRASH: AddressSanitizer: container-overflow |
| 37 | + // CHECK-CRASH: if you don't care about these errors you may set ASAN_OPTIONS=detect_container_overflow=0 |
| 38 | + return (int)t[60 * one]; // Touches the poisoned memory. |
30 | 39 | } |
31 | 40 |
|
32 | 41 | void BadBounds() { |
33 | 42 | long t[100]; |
34 | | -// CHECK-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container |
| 43 | +#if __has_feature(address_sanitizer) && !__ASAN_DISABLE_CONTAINER_OVERFLOW__ |
| 44 | + // CHECK-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container |
35 | 45 | __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 101, |
36 | 46 | &t[0] + 50); |
| 47 | +#endif |
37 | 48 | } |
38 | 49 |
|
39 | 50 | void UnalignedBadBounds() { |
40 | 51 | char t[100]; |
| 52 | +#if __has_feature(address_sanitizer) && !__ASAN_DISABLE_CONTAINER_OVERFLOW__ |
41 | 53 | // CHECK-UNALIGNED-BAD-BOUNDS: ERROR: AddressSanitizer: bad parameters to __sanitizer_annotate_contiguous_container |
42 | 54 | __sanitizer_annotate_contiguous_container(&t[1], &t[0] + 100, &t[0] + 101, |
43 | 55 | &t[0] + 50); |
| 56 | +#endif |
44 | 57 | } |
45 | 58 |
|
46 | 59 | int OddAlignment() { |
47 | 60 | int t[100]; |
48 | 61 | t[60] = 0; |
| 62 | +#if __has_feature(address_sanitizer) && !__ASAN_DISABLE_CONTAINER_OVERFLOW__ |
49 | 63 | __sanitizer_annotate_contiguous_container(&t[1], &t[0] + 100, &t[0] + 100, |
50 | 64 | &t[1] + 50); |
| 65 | +#endif |
51 | 66 | return (int)t[60 * one]; // Touches the poisoned memory. |
52 | 67 | } |
53 | 68 |
|
54 | 69 | int OddAlignmentEnd() { |
55 | 70 | int t[99]; |
56 | 71 | t[60] = 0; |
| 72 | +#if __has_feature(address_sanitizer) && !__ASAN_DISABLE_CONTAINER_OVERFLOW__ |
57 | 73 | __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 98, &t[0] + 98, |
58 | 74 | &t[0] + 50); |
| 75 | +#endif |
59 | 76 | return (int)t[60 * one]; // Touches the poisoned memory. |
60 | 77 | } |
61 | 78 |
|
|
0 commit comments