Skip to content

Commit 328021e

Browse files
committed
Improving HTML dump of taint summaries.
1 parent e957cd7 commit 328021e

File tree

1 file changed

+75
-8
lines changed

1 file changed

+75
-8
lines changed

src/taint-analysis/taint_summary_dump.cpp

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ dumper taint_condt::dump(const taint_tokent::named_tokenst &named_tokens) const
7272
});
7373
}
7474

75+
dumper taint_subject_conditiont::dump(
76+
const taint_tokent::named_tokenst &named_tokens) const
77+
{
78+
return dumper(
79+
[this, &named_tokens] (std::ostream &ostr)
80+
{
81+
ostr
82+
<< condition.get_name(named_tokens)
83+
<< " \u2208 " << subject;
84+
});
85+
}
86+
7587
void taint_functions_for_dumping_taint_summary_in_htmlt::
7688
taint_dump_lvalue_in_html(
7789
const taint_lvaluet &lvalue,
@@ -185,6 +197,31 @@ bool taint_functions_for_dumping_taint_summary_in_htmlt::
185197
const bool dump_differce_of_abstract_values,
186198
std::ostream& ostr)
187199
{
200+
ostr << "<table>\n"
201+
" <caption>Formal parameters of the function.</caption>\n"
202+
" <tr>\n"
203+
" <th>Index</th>\n"
204+
" <th>Name</th>\n"
205+
" <th>Type</th>\n"
206+
" </tr>\n"
207+
;
208+
assert(program.get_namespace().get_symbol_table().has_symbol(fn_id));
209+
const symbolt &fn_symbol=program.get_namespace().lookup(fn_id);
210+
const code_typet &fn_type=to_code_type(fn_symbol.type);
211+
for (std::size_t i=0UL, n=fn_type.parameters().size(); i!=n; ++i)
212+
{
213+
const code_typet::parametert &param=fn_type.parameters().at(i);
214+
ostr << " <tr>\n"
215+
" <td>" << i << "</td>\n"
216+
" <td>" << param.get_base_name() << "</td>\n"
217+
" <td>" << to_html_text(from_type(program.get_namespace(),"",
218+
param.type()))
219+
<< "</td>\n"
220+
" </tr>\n"
221+
;
222+
}
223+
ostr << "</table>\n";
224+
188225
ostr << "<h2>Taint summary</h2>\n"
189226
<< "<p>Mapping of input to symbols:</p>\n"
190227
"<table>\n"
@@ -257,9 +294,9 @@ bool taint_functions_for_dumping_taint_summary_in_htmlt::
257294
" <tr>\n"
258295
" <th>Loc</th>\n"
259296
" <th>Targets</th>\n"
260-
" <th style=\"width:150px;\">Instruction</th>\n"
261-
" <th style=\"width:150px;\">Domain value</th>\n"
262-
" <th>Comment</th>\n"
297+
" <th>Instruction</th>\n"
298+
" <th>Domain value</th>\n"
299+
" <th style=\"width:300px;\">Comment</th>\n"
263300
" </tr>\n";
264301
for (auto instr_it = fn_body.instructions.cbegin();
265302
instr_it!=fn_body.instructions.cend();
@@ -281,7 +318,7 @@ bool taint_functions_for_dumping_taint_summary_in_htmlt::
281318

282319
// Dumping instruction
283320
ostr << " <td>\n";
284-
dump_instruction_code_in_html(*instr_it, program.get_model(), ostr);
321+
dump_instruction_code_in_html(*instr_it, program.get_namespace(), ostr);
285322
ostr << "</td>\n";
286323

287324
// Dumping taint domain
@@ -339,16 +376,46 @@ bool taint_functions_for_dumping_taint_summary_in_htmlt::
339376
ostr << " Function summary was applied.";
340377
break;
341378
case taint_transition_property_typet::APPLICATION_OF_PROPAGATION_RULE:
342-
ostr << " Propagation rule was applied. ";
379+
ostr << " Propagation rule '"
380+
<< to_html_text(props.get_rule_id())
381+
<< "' was applied.";
343382
break;
344383
case taint_transition_property_typet::APPLICATION_OF_SANITISATION_RULE:
345-
ostr << " Sanitisation rule was applied.";
384+
ostr << " Sanitisation rule '"
385+
<< to_html_text(props.get_rule_id())
386+
<< "' was applied.";
346387
break;
347388
case taint_transition_property_typet::APPLICATION_OF_SINK_RULE:
348-
ostr << " Sink rule was applied.";
389+
ostr << " Sink rule '"
390+
<< to_html_text(props.get_rule_id())
391+
<< "' was applied.";
349392
break;
350393
case taint_transition_property_typet::CONDITIONAL_APPLICATION_OF_SINK_RULE:
351-
ostr << " The sink rule would be applied if conditions were met.";
394+
{
395+
ostr << " The sink rule '"
396+
<< to_html_text(props.get_rule_id())
397+
<< "' would be applied if ";
398+
bool first_and=true;
399+
for(const auto& set : props.get_sink_conditions())
400+
{
401+
if(!first_and)
402+
ostr << " and ";
403+
if(props.get_sink_conditions().size()>1U && set.size()>1U)
404+
ostr << " ( ";
405+
bool first_or=true;
406+
for(const auto& cond : set)
407+
{
408+
if(!first_or)
409+
ostr << " or ";
410+
ostr << html_encoding() << cond.dump(named_tokens);
411+
first_or=false;
412+
}
413+
if(props.get_sink_conditions().size()>1U && set.size()>1U)
414+
ostr << " ) ";
415+
first_and=false;
416+
}
417+
ostr << ".";
418+
}
352419
break;
353420
case taint_transition_property_typet::REMOVAL_OF_DEAD_VARIABLE:
354421
ostr << " Dead variable was removed from the domain.";

0 commit comments

Comments
 (0)