Skip to content

Commit 89d4a66

Browse files
NathanJPhillipssmowton
authored andcommitted
Merge pull request diffblue#123 from trtikm/cleanup/move-dump-into-taint_sett
Implemented proper dump of taint sets
1 parent 50f3006 commit 89d4a66

17 files changed

+238
-178
lines changed

src/goto-analyzer/taint_cond.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <boost/optional.hpp>
1010
#include <string>
1111
#include <util/json.h>
12+
#include <util/dumper.h>
1213

1314

1415
/*******************************************************************\
@@ -34,13 +35,15 @@ class taint_condt
3435

3536
//taint_sett substitute_for_variable(taint_variablet variable, taint_sett substitution);
3637

37-
boost::optional<taint_condt> recondition(taint_tokent condition2, taint_tokent result2)
38+
boost::optional<taint_condt> recondition(taint_tokent condition2, taint_tokent result2) const
3839
{
3940
if (result == condition2)
4041
return taint_condt(subject, condition, result2);
4142
return boost::none;
4243
}
4344

45+
dumper dump(const taint_tokent::named_tokenst &named_tokens) const;
46+
4447
size_t get_hash() const
4548
{
4649
std::size_t seed = 0;

src/goto-analyzer/taint_rules.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
boost::optional<tainted_locationt> tainted_locationt::load(
1111
const jsont &json,
12-
named_tokenst &tokens,
12+
taint_tokent::named_tokenst &tokens,
1313
message_handlert &message_handler)
1414
{
1515
messaget msg(message_handler);

src/goto-analyzer/taint_rules.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#include <string>
1616
#include <memory>
1717
#include <boost/optional.hpp>
18-
#include <boost/bimap.hpp>
19-
20-
21-
typedef boost::bimap<std::string, taint_tokent> named_tokenst;
2218

2319

2420
/*******************************************************************\
@@ -62,7 +58,7 @@ struct tainted_locationt
6258
public:
6359
static boost::optional<tainted_locationt> load(
6460
const jsont & json,
65-
named_tokenst &tokens,
61+
taint_tokent::named_tokenst &tokens,
6662
message_handlert &message_handler);
6763

6864
boost::optional<tainted_locationt> applied(
@@ -170,7 +166,7 @@ class taint_sink_rulet
170166
class taint_rulest
171167
{
172168
private:
173-
named_tokenst named_tokens;
169+
taint_tokent::named_tokenst named_tokens;
174170
std::map<irep_idt, std::shared_ptr<taint_propogation_rulet>> propogation_rules;
175171
std::map<irep_idt, std::shared_ptr<taint_sanitizer_rulet>> sanitizer_rules;
176172
std::map<irep_idt, std::shared_ptr<taint_sink_rulet>> sink_rules;

src/goto-analyzer/taint_set.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "taint_cond.h"
66
#include <string>
77
#include <util/json.h>
8+
#include <util/dumper.h>
89

910

1011
/*******************************************************************\
@@ -73,6 +74,8 @@ class taint_sett
7374
static taint_sett from_json(const jsont& js);
7475
json_objectt to_json() const;
7576

77+
dumper dump(const taint_tokent::named_tokenst &named_tokens) const;
78+
7679
//[[deprecated("External code should not access internal properties")]]
7780
const taint_variable_sett& get_vars() const { return variables; }
7881

src/goto-analyzer/taint_summary.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -571,19 +571,19 @@ static void build_summary_from_computed_domain(
571571
{
572572
msg.debug() << "o ";
573573
taint_dump_lvalue_in_html(lval, ns, msg.debug());
574-
msg.debug() << " &rarr; ";
575-
taint_dump_as_html(it->second, taint_variable_to_specification_symbol_name_mapt() /*TODO*/, msg.debug());
576-
msg.debug() << "\n";
574+
msg.debug() << " &rarr; "
575+
<< it->second.dump(taint_tokent::named_tokenst() /*TODO*/)
576+
<< "\n";
577577
}
578578
}
579579
else
580580
if(message_handler.get_verbosity()>=messaget::M_DEBUG)
581581
{
582582
msg.debug() << "o !! EXCLUDING !! : ";
583583
taint_dump_lvalue_in_html(lval, ns, msg.debug());
584-
msg.debug() << " &rarr; ";
585-
taint_dump_as_html(it->second, taint_variable_to_specification_symbol_name_mapt() /*TODO*/, msg.debug());
586-
msg.debug() << "\n";
584+
msg.debug() << " &rarr; "
585+
<< it->second.dump(taint_tokent::named_tokenst() /*TODO*/)
586+
<< "\n";
587587
}
588588
}
589589

src/goto-analyzer/taint_summary_dump.cpp

Lines changed: 73 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,66 @@ It provides a dump of computed taint summary in HTML format.
1414

1515
#include <goto-analyzer/taint_summary_dump.h>
1616
#include <util/msgstream.h>
17+
#include <util/string_join.h>
1718
#include <memory>
1819
#include <map>
1920
#include <sstream>
2021
#include <iostream>
2122
#include <iomanip>
2223
#include <cassert>
24+
#include <boost/range/adaptor/transformed.hpp>
2325

2426
void taint_dump_lvalue_in_html(
25-
taint_lvaluet const& lvalue,
26-
namespacet const& ns,
27-
std::ostream& ostr
28-
)
27+
taint_lvaluet const& lvalue,
28+
namespacet const& ns,
29+
std::ostream &ostr)
2930
{
3031
dump_access_path_in_html(lvalue,ns,ostr);
3132
}
3233

33-
void taint_dump_as_html(
34-
taint_sett const& taint,
35-
taint_variable_to_specification_symbol_name_mapt const&
36-
taint_spec_names,
37-
std::ostream& ostr
38-
)
34+
dumper taint_sett::dump(const taint_tokent::named_tokenst &named_tokens) const
3935
{
40-
if (taint.is_bottom())
41-
ostr << "&#8869;";
42-
else
43-
{
44-
bool first = true;
45-
for (auto const& symbol : taint.get_vars())
36+
return (dumper)
37+
[this, &named_tokens] (std::ostream &ostr)
4638
{
47-
ostr << (first ? "" : " <b>&#x2210;</b> ");
48-
auto const name_it = taint_spec_names.find(symbol);
49-
if (name_it != taint_spec_names.cend())
50-
ostr << name_it->second;
51-
else
52-
ostr << "T" << symbol;
53-
first = false;
54-
}
55-
}
39+
if (is_bottom())
40+
{
41+
ostr << "\u22A5";
42+
return;
43+
}
44+
std::string set_separator(" \u222A "),
45+
set_element_separator(", ");
46+
if(!tokens.empty() || !variables.empty())
47+
{
48+
ostr << "{ " << join(
49+
tokens
50+
| boost::adaptors::transformed([&named_tokens] (taint_tokent token)
51+
{ return token.get_name(named_tokens); }),
52+
set_element_separator);
53+
if(!tokens.empty())
54+
ostr << set_element_separator;
55+
ostr << join(variables, set_element_separator) << " }";
56+
if(!conditionals.empty())
57+
ostr << set_separator;
58+
}
59+
ostr << join(
60+
conditionals
61+
| boost::adaptors::transformed([&named_tokens] (taint_condt conditional)
62+
{ return conditional.dump(named_tokens); }),
63+
set_separator);
64+
};
65+
}
66+
67+
dumper taint_condt::dump(const taint_tokent::named_tokenst &named_tokens) const
68+
{
69+
return (dumper)
70+
[this, &named_tokens] (std::ostream &ostr)
71+
{
72+
ostr
73+
<< "(" << condition.get_name(named_tokens)
74+
<< " \u2208 " << subject
75+
<< " \u2192 " << result.get_name(named_tokens) << ")";
76+
};
5677
}
5778

5879
void lvalues_to_taint_dump_as_html(
@@ -77,13 +98,13 @@ void lvalues_to_taint_dump_as_html(
7798
ostr << " <table>\n";
7899
for (auto const& elem : order)
79100
{
80-
ostr << " <tr>\n";
81-
ostr << " <td>" << elem.first << "</td>\n";
82-
ostr << " <td>";
83-
taint_dump_as_html(lvalue_to_taint_map.at(elem.second),
84-
taint_spec_names,ostr);
85-
ostr << "</td>\n";
86-
ostr << " </tr>\n";
101+
ostr
102+
<< " <tr>\n"
103+
<< " <td>" << elem.first << "</td>\n"
104+
<< " <td>"
105+
<< lvalue_to_taint_map.at(elem.second).dump(taint_tokent::named_tokenst() /*TODO: Use taint_spec_names*/)
106+
<< "</td>\n"
107+
<< " </tr>\n";
87108
}
88109
ostr << " </table>\n";
89110
}
@@ -113,13 +134,13 @@ void numbered_lvalues_to_taint_dump_as_html(
113134
ostr << " <table>\n";
114135
for (auto const& elem : order)
115136
{
116-
ostr << " <tr>\n";
117-
ostr << " <td>" << elem.first << "</td>\n";
118-
ostr << " <td>";
119-
taint_dump_as_html(lvalue_to_taint_map.at(elem.second),
120-
taint_spec_names,ostr);
121-
ostr << "</td>\n";
122-
ostr << " </tr>\n";
137+
ostr
138+
<< " <tr>\n"
139+
<< " <td>" << elem.first << "</td>\n"
140+
<< " <td>"
141+
<< lvalue_to_taint_map.at(elem.second).dump(taint_tokent::named_tokenst() /*TODO: Use taint_spec_names*/)
142+
<< "</td>\n"
143+
<< " </tr>\n";
123144
}
124145
ostr << " </table>\n";
125146
}
@@ -177,7 +198,7 @@ void numbered_lvalues_to_taint_changes_dump_as_html(
177198
ostr << " <td>";
178199
auto findit=lvalue_to_taint_map.find(elem.second);
179200
if(findit!=lvalue_to_taint_map.end())
180-
taint_dump_as_html(findit->second,taint_spec_names,ostr);
201+
ostr << findit->second.dump(taint_tokent::named_tokenst() /*TODO: Use taint_spec_names*/);
181202
ostr << "</td>\n";
182203
ostr << " </tr>\n";
183204
}
@@ -218,13 +239,12 @@ std::string taint_object_summary_dump_as_html(
218239
}
219240
for (auto const& elem : order)
220241
{
221-
ostr << " <tr>\n";
222-
ostr << " <td>" << elem.first << "</td>\n";
223-
ostr << " <td>";
224-
taint_dump_as_html(summary->input().at(elem.second),
225-
taint_spec_names,ostr);
226-
ostr <<"</td>\n";
227-
ostr << " </tr>\n";
242+
ostr << " <tr>\n"
243+
<< " <td>" << elem.first << "</td>\n"
244+
<< " <td>"
245+
<< summary->input().at(elem.second).dump(taint_tokent::named_tokenst() /*TODO: Use taint_spec_names*/)
246+
<< "</td>\n"
247+
<< " </tr>\n";
228248
}
229249
}
230250
ostr << "</table>\n";
@@ -245,13 +265,12 @@ std::string taint_object_summary_dump_as_html(
245265
}
246266
for (auto const& elem : order)
247267
{
248-
ostr << " <tr>\n";
249-
ostr << " <td>" << elem.first << "</td>\n";
250-
ostr << " <td>";
251-
taint_dump_as_html(summary->output().at(elem.second),
252-
taint_spec_names,ostr);
253-
ostr <<"</td>\n";
254-
ostr << " </tr>\n";
268+
ostr << " <tr>\n"
269+
<< " <td>" << elem.first << "</td>\n"
270+
<< " <td>"
271+
<< summary->output().at(elem.second).dump(taint_tokent::named_tokenst() /*TODO: Use taint_spec_names*/)
272+
<< "</td>\n"
273+
<< " </tr>\n";
255274
}
256275
}
257276
ostr << "</table>\n";

src/goto-analyzer/taint_summary_dump.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,6 @@ void taint_dump_lvalue_in_html(
5252
Purpose:
5353
5454
55-
\*******************************************************************/
56-
void taint_dump_as_html(
57-
taint_sett const& taint,
58-
taint_variable_to_specification_symbol_name_mapt const&
59-
taint_spec_names,
60-
std::ostream& ostr
61-
);
62-
63-
64-
/*******************************************************************\
65-
66-
Function:
67-
68-
Inputs: See purpose
69-
70-
Outputs: See purpose
71-
72-
Purpose:
73-
74-
7555
\*******************************************************************/
7656
void lvalues_to_taint_dump_as_html(
7757
lvalue_to_taint_mapt const& lvalue_to_taint_map,

src/goto-analyzer/taint_token.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,3 @@ taint_tokent taint_tokent::fresh()
1212
static uint64_t last_id = 0;
1313
return taint_tokent(++last_id);
1414
}
15-
16-
std::string taint_tokent::to_string() const
17-
{
18-
return std::to_string(id);
19-
}

src/goto-analyzer/taint_token.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,32 @@
77
#else
88
# include <set>
99
#endif
10+
#include <boost/bimap.hpp>
1011

1112

1213
// An identifier for a concrete "taint state" of propagation from a source
1314
// to a sink.
1415
class taint_tokent : public id_as_struct<uint64_t>
1516
{
17+
public:
18+
typedef boost::bimap<std::string, taint_tokent> named_tokenst;
19+
1620
private:
1721
taint_tokent(uint64_t id);
1822

1923
public:
2024
static taint_tokent fresh();
2125

22-
std::string to_string() const;
26+
std::string get_name(named_tokenst names) const
27+
{
28+
return names.right.at(*this);
29+
}
30+
31+
friend std::ostream& operator<<(
32+
std::ostream &ostr, const taint_tokent& token)
33+
{
34+
return ostr << "T" << static_cast<const id_as_struct<uint64_t> &>(token);
35+
}
2336
};
2437

2538
namespace std

src/goto-analyzer/taint_trace_dump_html.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,13 @@ void taint_trace_dump_as_html(
114114
taint_spec_names,
115115
ostr
116116
);
117-
ostr << " </td>\n"
118-
" <td>\n";
119-
taint_dump_as_html(
120-
element.get_taint(),
121-
taint_spec_names,
122-
ostr
123-
);
124-
ostr << " </td>\n"
125-
" <td>" << to_html_text(element.get_message())
126-
<< "</td>\n"
127-
" <td>"
128-
;
117+
ostr
118+
<< " </td>\n"
119+
" <td>\n"
120+
<< element.get_taint().dump(taint_tokent::named_tokenst() /*TODO: use taint_spec_names*/)
121+
<< " </td>\n"
122+
" <td>" << to_html_text(element.get_message()) << "</td>\n"
123+
" <td>";
129124
if (element.get_line() != 0UL)
130125
ostr << element.get_line();
131126
else

0 commit comments

Comments
 (0)