@@ -55,21 +55,21 @@ taint_tokens_propagation_grapht::taint_tokens_propagation_grapht(
55
55
if (propagation_rule->has_input_condition ())
56
56
{
57
57
insert_forward_relation_from_token_to_rule (
58
- names_of_tokens.right .at (propagation_rule->get_input_taint ()), id);
59
- map_from_rules_to_inputs[id]. insert (
58
+ names_of_tokens.right .at (propagation_rule->get_input_taint ()),
59
+ id,
60
60
propagation_rule->get_input_location ().arg_index );
61
61
}
62
62
else
63
63
{
64
- insert_forward_relation_from_token_to_rule (get_source_token (), id);
65
- // We have to make sure that there is created a set (empty) for
66
- // the rule of map from rules to input.
67
- map_from_rules_to_inputs[id]={} ;
64
+ insert_forward_relation_from_token_to_rule (
65
+ get_source_token (),
66
+ id,
67
+ get_void_loc ()) ;
68
68
}
69
69
70
70
insert_forward_relation_from_rule_to_token (
71
- id, names_of_tokens. right . at (propagation_rule-> get_result_taint ()));
72
- map_from_rules_to_outputs[id]. insert (
71
+ id,
72
+ names_of_tokens. right . at (propagation_rule-> get_result_taint ()),
73
73
translate_taintable_location (propagation_rule->get_result_location ()));
74
74
}
75
75
}
@@ -82,13 +82,13 @@ taint_tokens_propagation_grapht::taint_tokens_propagation_grapht(
82
82
const rule_idt id=std::to_string (sanitizer_rule->get_id ());
83
83
84
84
insert_forward_relation_from_token_to_rule (
85
- names_of_tokens.right .at (sanitizer_rule->get_sanitized_taint ()), id);
86
- // We have to make sure that there is created a set (empty) for
87
- // the rule of map from rules to input.
88
- map_from_rules_to_inputs[id]={};
89
- map_from_rules_to_outputs[id].insert (
85
+ names_of_tokens.right .at (sanitizer_rule->get_sanitized_taint ()),
86
+ id,
87
+ get_void_loc ());
88
+ insert_forward_relation_from_rule_to_token (
89
+ id,
90
+ get_source_token (),
90
91
translate_taintable_location (sanitizer_rule->get_sanitized_location ()));
91
-
92
92
sanitisers.insert (id);
93
93
}
94
94
}
@@ -103,36 +103,27 @@ taint_tokens_propagation_grapht::taint_tokens_propagation_grapht(
103
103
if (sink_rule->has_input_condition ())
104
104
{
105
105
insert_forward_relation_from_token_to_rule (
106
- names_of_tokens.right .at (sink_rule->get_input_taint ()), id);
107
- map_from_rules_to_inputs[id]. insert (
106
+ names_of_tokens.right .at (sink_rule->get_input_taint ()),
107
+ id,
108
108
sink_rule->get_input_location ().arg_index );
109
109
}
110
110
else
111
- insert_forward_relation_from_token_to_rule (get_source_token (), id);
112
-
111
+ {
112
+ insert_forward_relation_from_token_to_rule (
113
+ get_source_token (),
114
+ id,
115
+ get_void_loc ());
116
+ }
113
117
insert_forward_relation_from_token_to_rule (
114
- names_of_tokens.right .at (sink_rule->get_sink_target_taint ()), id);
115
- insert_forward_relation_from_rule_to_token (id, get_sink_token ());
116
- map_from_rules_to_inputs[id].insert (
118
+ names_of_tokens.right .at (sink_rule->get_sink_target_taint ()),
119
+ id,
117
120
translate_taintable_location (sink_rule->get_sink_target_location ()));
118
- // We also have to make sure that there is created a set (empty) for
119
- // the rule of map from rules to output.
120
- map_from_rules_to_outputs[id]={};
121
+ insert_forward_relation_from_rule_to_token (
122
+ id,
123
+ get_sink_token (),
124
+ get_void_loc ());
121
125
}
122
126
}
123
- // Sanitisers require a special handling: we have to insert edges from
124
- // a sanitasition rule into all tokens representing a propagation of tainted
125
- // data without the sanitised taint.
126
- for (const auto &sanitiser : sanitisers)
127
- // For each token (sanitised) leading to the sanitisation rule.
128
- for (const auto &sanitised_token : get_backward_tokens_from_rule (sanitiser))
129
- // For each rule leading to the token later sanitised by the sanitisation
130
- // rule.
131
- for (const auto &rule : get_backward_rules_from_token (sanitised_token))
132
- // For each token not affected by the sanitisation rule, but whose
133
- // (some) successor rules may lead to token which is later sanitised.
134
- for (const auto &token : get_backward_tokens_from_rule (rule))
135
- insert_forward_relation_from_rule_to_token (sanitiser, token);
136
127
std::sort (tokens.begin (), tokens.end ());
137
128
std::sort (rules.begin (), rules.end ());
138
129
}
@@ -158,46 +149,35 @@ void taint_tokens_propagation_grapht::insert_rule(const rule_idt &rid)
158
149
rules.push_back (rid);
159
150
forward_map_from_rules_to_tokens[rid]={};
160
151
backward_map_from_rules_to_tokens[rid]={};
152
+ map_from_rules_to_inputs[rid]={};
153
+ map_from_rules_to_outputs[rid]={};
161
154
}
162
155
}
163
156
164
157
void taint_tokens_propagation_grapht::
165
158
insert_forward_relation_from_token_to_rule (
166
159
const taint_tokent::namet &tid,
167
- const rule_idt &rid)
160
+ const rule_idt &rid,
161
+ const int loc)
168
162
{
169
163
insert_token (tid);
170
164
insert_rule (rid);
171
- {
172
- auto &out_rules=forward_map_from_tokens_to_rules[tid];
173
- if (std::find (out_rules.cbegin (), out_rules.cend (), rid)==out_rules.cend ())
174
- out_rules.push_back (rid);
175
- }
176
- {
177
- auto &in_tokens=backward_map_from_rules_to_tokens[rid];
178
- if (std::find (in_tokens.cbegin (), in_tokens.cend (), tid)==in_tokens.cend ())
179
- in_tokens.push_back (tid);
180
- }
165
+ forward_map_from_tokens_to_rules[tid].push_back (rid);
166
+ backward_map_from_rules_to_tokens[rid].push_back (tid);
167
+ map_from_rules_to_inputs[rid].push_back (loc);
181
168
}
182
169
183
170
void taint_tokens_propagation_grapht::
184
171
insert_forward_relation_from_rule_to_token (
185
172
const rule_idt &rid,
186
- const taint_tokent::namet &tid)
173
+ const taint_tokent::namet &tid,
174
+ const int loc)
187
175
{
188
176
insert_token (tid);
189
177
insert_rule (rid);
190
- {
191
- auto &out_tokens=forward_map_from_rules_to_tokens[rid];
192
- if (std::find (out_tokens.cbegin (), out_tokens.cend (), tid)==
193
- out_tokens.cend ())
194
- out_tokens.push_back (tid);
195
- }
196
- {
197
- auto &in_rules=backward_map_from_tokens_to_rules[tid];
198
- if (std::find (in_rules.cbegin (), in_rules.cend (), rid)==in_rules.cend ())
199
- in_rules.push_back (rid);
200
- }
178
+ forward_map_from_rules_to_tokens[rid].push_back (tid);
179
+ backward_map_from_tokens_to_rules[tid].push_back (rid);
180
+ map_from_rules_to_outputs[rid].push_back (loc);
201
181
}
202
182
203
183
std::ostream &taint_to_dot (
@@ -208,18 +188,27 @@ std::ostream &taint_to_dot(
208
188
<< " rankdir=TB;\n "
209
189
<< " node [fontsize=12];\n\n " ;
210
190
for (const taint_tokent::namet &token : graph.get_tokens ())
191
+ {
211
192
ostr << " \" " << token
212
- << " \" [label=\" "
213
- << (token == taint_tokens_propagation_grapht::get_source_token () ?
214
- taint_tokens_propagation_grapht::get_source_token ().name :
215
- token == taint_tokens_propagation_grapht::get_sink_token () ?
216
- taint_tokens_propagation_grapht::get_sink_token ().name :
217
- (msgstream () << token).get ())
218
- << " \" , shape="
219
- << (token==graph.get_source_token () ? " octagon" :
220
- (token==graph.get_sink_token () ? " doubleoctagon" :
221
- " ellipse" ))
222
- << " ];\n " ;
193
+ << " \" [label=\" " ;
194
+ if (token == taint_tokens_propagation_grapht::get_source_token ())
195
+ {
196
+ ostr << taint_tokens_propagation_grapht::get_source_token ().name
197
+ << " \" , shape=octagon, style=filled, fillcolor=aquamarine" ;
198
+ }
199
+ else if (token == taint_tokens_propagation_grapht::get_sink_token ())
200
+ {
201
+ ostr << taint_tokens_propagation_grapht::get_sink_token ().name
202
+ << " \" , shape=doubleoctagon, style=filled, fillcolor=lightcoral" ;
203
+ }
204
+ else
205
+ {
206
+ ostr << token << " \" , shape=ellipse" ;
207
+ if (graph.get_forward_rules_from_token (token).empty ())
208
+ ostr << " , style=filled, fillcolor=gold" ;
209
+ }
210
+ ostr << " ];\n " ;
211
+ }
223
212
ostr << " \n " ;
224
213
for (const auto &rule : graph.get_rules ())
225
214
{
@@ -236,42 +225,74 @@ std::ostream &taint_to_dot(
236
225
bool first=true ;
237
226
for (const auto index : graph.get_map_from_rules_to_inputs ().at (rule))
238
227
{
239
- if (!first)
240
- ostr << " , " ;
241
- ostr << " ARG" << index ;
242
- first=false ;
228
+ if (index !=taint_tokens_propagation_grapht::get_void_loc ())
229
+ {
230
+ if (!first)
231
+ ostr << " , " ;
232
+ ostr << " ARG" << index ;
233
+ first=false ;
234
+ }
243
235
}
244
236
ostr << " }\\ lOUTPUTS: {" ;
245
237
first=true ;
246
238
for (const auto index : graph.get_map_from_rules_to_outputs ().at (rule))
247
239
{
248
- if (!first)
249
- ostr << " , " ;
250
- if (index <0 )
251
- ostr << " RETVAL" ;
252
- else
253
- ostr << " ARG" << index ;
254
- first=false ;
240
+ if (index !=taint_tokens_propagation_grapht::get_void_loc ())
241
+ {
242
+ if (!first)
243
+ ostr << " , " ;
244
+ if (index ==-1 )
245
+ ostr << " RETVAL" ;
246
+ else
247
+ ostr << " ARG" << index ;
248
+ first=false ;
249
+ }
255
250
}
256
251
ostr << " }\\ l\" , shape=box"
257
252
<< (graph.get_sanitiser_rules ().count (rule)!=0UL ?
258
253
" , style=filled, fillcolor=lightgray" :
259
- " " )
254
+ " , style=filled, fillcolor=azure " )
260
255
<< " ];\n " ;
261
256
}
262
257
ostr << " \n " ;
263
- for (const auto &token : graph.get_tokens ())
258
+
259
+ for (const auto &rule : graph.get_rules ())
264
260
{
265
- for (const auto &rule : graph.get_forward_rules_from_token (token))
266
- ostr << " \" " << token
267
- << " \" -> "
268
- << " \" " << rule
269
- << " \" ;\n " ;
270
- for (const auto &rule : graph.get_backward_rules_from_token (token))
271
- ostr << " \" " << rule
272
- << " \" -> "
273
- << " \" " << token
274
- << " \" ;\n " ;
261
+ const auto &in_tokens=graph.get_backward_tokens_from_rule (rule);
262
+ const auto &in_locs=graph.get_map_from_rules_to_inputs ().at (rule);
263
+ assert (in_tokens.size ()==in_locs.size ());
264
+ for (std::size_t i=0UL , n=in_tokens.size (); i!=n; ++i)
265
+ {
266
+ ostr << " \" " << in_tokens.at (i) << " \" -> \" " << rule << " \" " ;
267
+ if (in_locs.at (i)!=taint_tokens_propagation_grapht::get_void_loc ())
268
+ {
269
+ ostr << " [label=\" " ;
270
+ if (in_locs.at (i)==-1 )
271
+ ostr << " RETVAL" ;
272
+ else
273
+ ostr << " ARG" << in_locs.at (i);
274
+ ostr << " \" ]" ;
275
+ }
276
+ ostr << " \n " ;
277
+ }
278
+
279
+ const auto &out_tokens=graph.get_forward_tokens_from_rule (rule);
280
+ const auto &out_locs=graph.get_map_from_rules_to_outputs ().at (rule);
281
+ assert (out_tokens.size ()==out_locs.size ());
282
+ for (std::size_t i=0UL , n=out_tokens.size (); i!=n; ++i)
283
+ {
284
+ ostr << " \" " << rule << " \" -> \" " << out_tokens.at (i) << " \" " ;
285
+ if (out_locs.at (i)!=taint_tokens_propagation_grapht::get_void_loc ())
286
+ {
287
+ ostr << " [label=\" " ;
288
+ if (out_locs.at (i)==-1 )
289
+ ostr << " RETVAL" ;
290
+ else
291
+ ostr << " ARG" << out_locs.at (i);
292
+ ostr << " \" ]" ;
293
+ }
294
+ ostr << " \n " ;
295
+ }
275
296
}
276
297
ostr << " }\n " ;
277
298
0 commit comments