1// RUN: %clang_asan -O0 %s -o %t
2// RUN: %run %t 0x00 2>&1 | FileCheck %s -check-prefix=X00
3// RUN: not %run %t 0xf1 2>&1 | FileCheck %s -check-prefix=XF1
4// RUN: not %run %t 0xf2 2>&1 | FileCheck %s -check-prefix=XF2
5// RUN: not %run %t 0xf3 2>&1 | FileCheck %s -check-prefix=XF3
6// RUN: not %run %t 0xf5 2>&1 | FileCheck %s -check-prefix=XF5
7// RUN: not %run %t 0xf8 2>&1 | FileCheck %s -check-prefix=XF8
8
9#include <assert.h>
10#include <sanitizer/asan_interface.h>
11#include <stddef.h>
12#include <stdio.h>
13#include <stdlib.h>
14
15void __asan_set_shadow_00(size_t addr, size_t size);
16void __asan_set_shadow_01(size_t addr, size_t size);
17void __asan_set_shadow_02(size_t addr, size_t size);
18void __asan_set_shadow_03(size_t addr, size_t size);
19void __asan_set_shadow_04(size_t addr, size_t size);
20void __asan_set_shadow_05(size_t addr, size_t size);
21void __asan_set_shadow_06(size_t addr, size_t size);
22void __asan_set_shadow_07(size_t addr, size_t size);
23void __asan_set_shadow_f1(size_t addr, size_t size);
24void __asan_set_shadow_f2(size_t addr, size_t size);
25void __asan_set_shadow_f3(size_t addr, size_t size);
26void __asan_set_shadow_f5(size_t addr, size_t size);
27void __asan_set_shadow_f8(size_t addr, size_t size);
28
29char* a;
30
31void f(long arg) {
32 size_t shadow_offset;
33 size_t shadow_scale;
34 __asan_get_shadow_mapping(shadow_scale: &shadow_scale, shadow_offset: &shadow_offset);
35 size_t addr = (((size_t)a) >> shadow_scale) + shadow_offset;
36
37 switch (arg) {
38 // X00-NOT: AddressSanitizer
39 // X00: PASS
40 case 0x00:
41 return __asan_set_shadow_00(addr, size: 1);
42 // X01: AddressSanitizer: stack-buffer-overflow
43 // X01: [01]
44 case 0x01:
45 return __asan_set_shadow_01(addr, size: 1);
46 // X02: AddressSanitizer: stack-buffer-overflow
47 // X02: [02]
48 case 0x02:
49 return __asan_set_shadow_02(addr, size: 1);
50 // X03: AddressSanitizer: stack-buffer-overflow
51 // X03: [03]
52 case 0x03:
53 return __asan_set_shadow_03(addr, size: 1);
54 // X04: AddressSanitizer: stack-buffer-overflow
55 // X04: [04]
56 case 0x04:
57 return __asan_set_shadow_04(addr, size: 1);
58 // X05: AddressSanitizer: stack-buffer-overflow
59 // X05: [05]
60 case 0x05:
61 return __asan_set_shadow_05(addr, size: 1);
62 // X06: AddressSanitizer: stack-buffer-overflow
63 // X06: [06]
64 case 0x06:
65 return __asan_set_shadow_06(addr, size: 1);
66 // X07: AddressSanitizer: stack-buffer-overflow
67 // X07: [07]
68 case 0x07:
69 return __asan_set_shadow_07(addr, size: 1);
70 // XF1: AddressSanitizer: stack-buffer-underflow
71 // XF1: [f1]
72 case 0xf1:
73 return __asan_set_shadow_f1(addr, size: 1);
74 // XF2: AddressSanitizer: stack-buffer-overflow
75 // XF2: [f2]
76 case 0xf2:
77 return __asan_set_shadow_f2(addr, size: 1);
78 // XF3: AddressSanitizer: stack-buffer-overflow
79 // XF3: [f3]
80 case 0xf3:
81 return __asan_set_shadow_f3(addr, size: 1);
82 // XF5: AddressSanitizer: stack-use-after-return
83 // XF5: [f5]
84 case 0xf5:
85 return __asan_set_shadow_f5(addr, size: 1);
86 // XF8: AddressSanitizer: stack-use-after-scope
87 // XF8: [f8]
88 case 0xf8:
89 return __asan_set_shadow_f8(addr, size: 1);
90 }
91 assert(0);
92}
93
94int main(int argc, char **argv) {
95 assert(argc > 1);
96
97 a = malloc(size: 8);
98 long arg = strtol(nptr: argv[1], endptr: 0, base: 16);
99 f(arg);
100 *a = 1;
101 printf(format: "PASS\n");
102 return 0;
103}
104

source code of compiler-rt/test/asan/TestCases/set_shadow_test.c