1
- /* ****************************************************************** \
1
+ /* ******************************************************************\
2
2
3
3
Module: taint_svalue
4
4
@@ -10,34 +10,58 @@ This module defines the structure of symbolic expressions. A symbolic expression
10
10
is an abstract value assigned to a memmory access path. This module is related
11
11
to the summary based taint analysis.
12
12
13
- @ Copyright Diffblue , Ltd.
13
+ @ Copyright DiffBlue , Ltd.
14
14
15
15
\*******************************************************************/
16
16
17
17
#include < goto-analyzer/taint_svalue.h>
18
18
#include < algorithm>
19
19
20
20
21
+ cond_suppression_idt get_fresh_cond_suppression_id ()
22
+ {
23
+ static cond_suppression_idt id = 0ULL ;
24
+ return ++id;
25
+ }
26
+
27
+ taint_token_suppressiont::taint_token_suppressiont (
28
+ const taint_set_of_svarst &in_vars,
29
+ const cond_suppression_idt in_cond_suppression_id
30
+ )
31
+ : vars(in_vars)
32
+ , cond_suppression_id(in_cond_suppression_id)
33
+ {}
34
+
35
+ void taint_token_suppressiont::insert (const taint_set_of_svarst &in_vars)
36
+ {
37
+ vars.insert (in_vars.cbegin (),in_vars.cend ());
38
+ }
39
+
40
+
21
41
taint_svaluet::taint_svaluet (
22
42
const taint_set_of_tokenst &in_tokens,
23
43
const taint_set_of_svarst &in_vars,
24
- const taint_set_of_condst &in_conds
44
+ const taint_set_of_condst &in_conds,
45
+ const taint_set_of_token_suppressionst &in_suppressions
25
46
)
26
47
: tokens(in_tokens)
27
48
, vars(in_vars)
28
49
, conds(in_conds.cbegin(),in_conds.cend())
50
+ , suppressions(in_suppressions)
29
51
{}
30
52
31
53
taint_svaluet::taint_svaluet ()
32
54
: tokens()
33
55
, vars()
34
56
, conds()
57
+ , suppressions()
35
58
{}
36
59
37
60
taint_svaluet::taint_svaluet (const taint_svaluet &other)
38
61
: tokens(other.get_tokens())
39
62
, vars(other.get_vars())
40
63
, conds(other.get_conds().cbegin(),other.get_conds().cend())
64
+ , suppressions(other.get_suppressions())
41
65
{
42
66
}
43
67
@@ -54,16 +78,49 @@ void taint_svaluet::join(const taint_svaluet &other)
54
78
vars.insert (other.get_vars ().cbegin (),other.get_vars ().cend ());
55
79
#endif
56
80
conds.insert (other.get_conds ().cbegin (),other.get_conds ().cend ());
81
+ suppressions.insert (other.get_suppressions ().cbegin (),
82
+ other.get_suppressions ().cend ());
57
83
}
58
84
85
+ void taint_svaluet::suppress (const taint_tokent token)
86
+ {
87
+ tokens.erase (token);
88
+
89
+ cond_suppression_idt cond_suppression_id;
90
+ auto it = suppressions.find (token);
91
+ if (it == suppressions.end ())
92
+ {
93
+ cond_suppression_id = get_fresh_cond_suppression_id ();
94
+ it = suppressions.insert ({token,{get_vars (),cond_suppression_id}}).first ;
95
+ }
96
+ else
97
+ {
98
+ cond_suppression_id = it->second .get_cond_suppression_id ();
99
+ it->second .insert (get_vars ());
100
+ }
101
+
102
+ taint_set_of_condst new_conds;
103
+ for (auto & cond : conds)
104
+ {
105
+ taint_condt tmp = cond;
106
+ tmp.insert (cond_suppression_id);
107
+ new_conds.insert (tmp);
108
+ }
109
+ using std::swap;
110
+ swap (new_conds,conds);
111
+ }
112
+
113
+
59
114
taint_condt::taint_condt (
60
115
const std::vector<taint_tokent> &in_tested_symbols,
61
116
const std::vector<taint_svaluet> &in_conditionals,
62
- const taint_svaluet &in_result
117
+ const taint_svaluet &in_result,
118
+ const taint_set_of_cond_suppression_idst in_suppression_ids
63
119
)
64
120
: tested_symbols(in_tested_symbols)
65
121
, conditionals(in_conditionals)
66
122
, result(in_result)
123
+ , suppression_ids(in_suppression_ids)
67
124
{}
68
125
69
126
@@ -75,20 +132,21 @@ taint_svaluet taint_make_symbol()
75
132
76
133
taint_svaluet taint_make_symbol (const taint_symbolic_variablet svar)
77
134
{
78
- return {{},{svar},{}};
135
+ return {{},{svar},{},{} };
79
136
}
80
137
81
138
82
139
taint_svaluet taint_make_bottom ()
83
140
{
84
- return {{},{},{}};
141
+ return {{},{},{},{} };
85
142
}
86
143
87
144
bool equal (const taint_svaluet &a, const taint_svaluet &b)
88
145
{
89
146
return a.get_tokens () == b.get_tokens () &&
90
147
a.get_vars () == b.get_vars () &&
91
- a.get_conds () == b.get_conds ()
148
+ a.get_conds () == b.get_conds () &&
149
+ a.get_suppressions () == b.get_suppressions ()
92
150
;
93
151
}
94
152
@@ -120,6 +178,10 @@ bool proper_subset(const taint_svaluet &a, const taint_svaluet &b)
120
178
if (b.get_conds ().count (elem) == 0ULL )
121
179
return false ;
122
180
181
+ // TODO: this condition should be improved!
182
+ if (!(a.get_suppressions () == b.get_suppressions ()))
183
+ return false ;
184
+
123
185
return true ;
124
186
}
125
187
@@ -130,15 +192,29 @@ taint_svaluet join(const taint_svaluet &a, const taint_svaluet &b)
130
192
return result;
131
193
}
132
194
195
+ taint_svaluet suppress (const taint_svaluet &a, const taint_tokent token)
196
+ {
197
+ taint_svaluet result=a;
198
+ result.suppress (token);
199
+ return result;
200
+ }
201
+
133
202
134
203
bool operator ==(const taint_condt &a, const taint_condt &b)
135
204
{
136
205
return a.get_tested_symbols () == b.get_tested_symbols () &&
137
206
a.get_conditionals () == b.get_conditionals () &&
138
- a.get_result_expression () == b.get_result_expression ()
207
+ a.get_result_expression () == b.get_result_expression () &&
208
+ a.get_suppression_ids () == b.get_suppression_ids ()
139
209
;
140
210
}
141
211
212
+ bool operator ==(const taint_token_suppressiont &a,
213
+ const taint_token_suppressiont &b)
214
+ {
215
+ return a.get_cond_suppression_id () == b.get_cond_suppression_id () &&
216
+ a.get_vars () == a.get_vars ();
217
+ }
142
218
143
219
144
220
// taint_svaluet suppression(
0 commit comments