-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathaliasing.cpp
More file actions
268 lines (213 loc) · 4.45 KB
/
aliasing.cpp
File metadata and controls
268 lines (213 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
int user_input();
void sink(int);
struct S {
int m1, m2;
};
void pointerSetter(S *s) {
s->m1 = user_input();
}
void referenceSetter(S &s) {
s.m1 = user_input();
}
void copySetter(S s) {
s.m1 = user_input();
}
void callSetters() {
S s1 = { 0, 0 };
S s2 = { 0, 0 };
S s3 = { 0, 0 };
pointerSetter(&s1);
referenceSetter(s2);
copySetter(s3);
sink(s1.m1); // $ ast,ir
sink(s2.m1); // $ ast,ir
sink(s3.m1); // no flow
}
void assignAfterAlias() {
S s1 = { 0, 0 };
S &ref1 = s1;
ref1.m1 = user_input();
sink(s1.m1); // $ MISSING: ast,ir
S s2 = { 0, 0 };
S &ref2 = s2;
s2.m1 = user_input();
sink(ref2.m1); // $ MISSING: ast,ir
}
void assignAfterCopy() {
S s1 = { 0, 0 };
S copy1 = s1;
copy1.m1 = user_input();
sink(s1.m1); // no flow
S s2 = { 0, 0 };
S copy2 = s2;
s2.m1 = user_input();
sink(copy2.m1); // no flow
}
void assignBeforeCopy() {
S s2 = { 0, 0 };
s2.m1 = user_input();
S copy2 = s2;
sink(copy2.m1); // $ ast,ir
}
struct Wrapper {
S s;
};
void copyIntermediate() {
Wrapper w = { { 0, 0 } };
S s = w.s;
s.m1 = user_input();
sink(w.s.m1); // no flow
}
void pointerIntermediate() {
Wrapper w = { { 0, 0 } };
S *s = &w.s;
s->m1 = user_input();
sink(w.s.m1); // $ MISSING: ast,ir
}
void referenceIntermediate() {
Wrapper w = { { 0, 0 } };
S &s = w.s;
s.m1 = user_input();
sink(w.s.m1); // $ MISSING: ast,ir
}
void nestedAssign() {
Wrapper w = { { 0, 0 } };
w.s.m1 = user_input();
sink(w.s.m1); // $ ast,ir
}
void addressOfField() {
S s;
s.m1 = user_input();
S s_copy = s;
int* px = &s_copy.m1;
sink(*px); // $ ir MISSING: ast
}
void taint_a_ptr(int* pa) {
*pa = user_input();
}
void test_field_conflation_array_content() {
S s;
taint_a_ptr(&s.m1);
sink(s.m2);
}
struct S_with_pointer {
int m1, m2;
int* data;
};
void pointer_deref(int* xs) {
taint_a_ptr(xs);
sink(xs[0]); // $ ir MISSING: ast
}
void pointer_deref_sub(int* xs) {
taint_a_ptr(xs - 2);
sink(*(xs - 2)); // $ ir MISSING: ast
}
void pointer_many_addrof_and_deref(int* xs) {
taint_a_ptr(xs);
sink(*&*&*xs); // $ ir MISSING: ast
}
void pointer_unary_plus(int* xs) {
taint_a_ptr(+xs);
sink(*+xs); // $ ir MISSING: ast
}
void pointer_member_index(S_with_pointer s) {
taint_a_ptr(s.data);
// `s.data` is points to all-aliased-memory
sink(s.data[0]); // $ ir MISSING: ast
}
void member_array_different_field(S_with_pointer* s) {
taint_a_ptr(&s[0].m1);
sink(s[0].m2);
}
struct S_with_array {
int m1, m2;
int data[10];
};
void pointer_member_deref() {
S_with_array s;
taint_a_ptr(s.data);
sink(*s.data); // $ ast,ir
}
void array_member_deref() {
S_with_array s;
taint_a_ptr(s.data);
sink(s.data[0]); // $ ast,ir
}
struct S2 {
S s;
int m3;
};
void deep_member_field_dot() {
S2 s2;
taint_a_ptr(&s2.s.m1);
sink(s2.s.m1); // $ ir,ast
}
void deep_member_field_dot_different_fields() {
S2 s2;
taint_a_ptr(&s2.s.m1);
sink(s2.s.m2);
}
void deep_member_field_dot_2() {
S2 s2;
taint_a_ptr(&s2.s.m1);
S2 s2_2 = s2;
sink(s2_2.s.m1); // $ ir,ast
}
void deep_member_field_dot_different_fields_2() {
S2 s2;
taint_a_ptr(&s2.s.m1);
S2 s2_2 = s2;
sink(s2_2.s.m2);
}
void deep_member_field_arrow(S2 *ps2) {
taint_a_ptr(&ps2->s.m1);
sink(ps2->s.m1); // $ ir,ast
}
void deep_member_field_arrow_different_fields(S2 *ps2) {
taint_a_ptr(&ps2->s.m1);
sink(ps2->s.m2);
}
namespace GlobalFieldFlow {
S global_s;
S2 global_s2;
void set_field() {
global_s.m1 = user_input();
}
void read_field() {
sink(global_s.m1); // $ ir MISSING: ast
}
void set_nested_field() {
global_s2.s.m1 = user_input();
}
void read_nested_field() {
sink(global_s2.s.m1); // $ ir MISSING: ast
}
S* global_s_ptr;
S2* global_s2_ptr;
void set_field_ptr() {
global_s_ptr->m1 = user_input();
}
void read_field_ptr() {
sink(global_s_ptr->m1); // $ ir MISSING: ast
}
void set_nested_field_ptr() {
global_s2_ptr->s.m1 = user_input();
}
void read_nested_field_ptr() {
sink(global_s2_ptr->s.m1); // $ ir MISSING: ast
}
S_with_pointer global_s_with_pointer;
void set_field_indirect() {
*global_s_with_pointer.data = user_input();
}
void read_field_indirect() {
sink(*global_s_with_pointer.data); // $ ir MISSING: ast
}
S_with_array global_s_with_array;
void set_field_array() {
*global_s_with_array.data = user_input();
}
void read_field_array() {
sink(*global_s_with_array.data); // $ ir MISSING: ast
}
}