Skip to content

Commit 1715d9a

Browse files
NathanJPhillipssmowton
authored andcommitted
Merge pull request diffblue#103 from trtikm/security_scanner__extended_expressivity_PR
Added support of suppression of tokens (enabling the sanitisation).
1 parent 6c303bb commit 1715d9a

File tree

8 files changed

+213
-45
lines changed

8 files changed

+213
-45
lines changed

src/cbmc.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// ADD PREDEFINED MACROS HERE!
2-
#define __cplusplus 201103
2+
#define USE_BOOST

src/goto-analyzer/taint_summary.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ static void build_substituted_summary(
514514
}
515515
substituted_summary.insert({
516516
lhs,
517+
// TODO: Do apply suppression here!!
517518
substituted_svalue //suppression(substituted_svalue,lvalue_svalue.second.suppression())
518519
});
519520
}

src/goto-analyzer/taint_summary_dump.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,17 @@ void taint_dump_svalue_in_html(
5252
ostr << "T" << symbol;
5353
first = false;
5454
}
55-
// if (!svalue.suppression().empty())
56-
// ostr << " <b>\\</b> ";
57-
// first = true;
58-
// for (auto const& symbol : svalue.suppression())
59-
// {
60-
// ostr << (first ? "" : " <b>&#x2210;</b> ");
61-
// auto const name_it = taint_spec_names.find(symbol);
62-
// if (name_it != taint_spec_names.cend())
63-
// ostr << name_it->second;
64-
// else
65-
// ostr << "T" << symbol;
66-
// first = false;
67-
// }
55+
if (!svalue.get_suppressions().empty())
56+
{
57+
ostr << " <b>\\</b> ";
58+
//first = true;
59+
for (auto const& token_sets : svalue.get_suppressions())
60+
{
61+
//ostr << (first ? "" : " <b>&#x2210;</b> ");
62+
ostr << "X" << token_sets.first << " ";
63+
//first = false;
64+
}
65+
}
6866
}
6967
}
7068

src/goto-analyzer/taint_svalue.cpp

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/******************************************************************* \
1+
/*******************************************************************\
22
33
Module: taint_svalue
44
@@ -10,34 +10,58 @@ This module defines the structure of symbolic expressions. A symbolic expression
1010
is an abstract value assigned to a memmory access path. This module is related
1111
to the summary based taint analysis.
1212
13-
@ Copyright Diffblue, Ltd.
13+
@ Copyright DiffBlue, Ltd.
1414
1515
\*******************************************************************/
1616

1717
#include <goto-analyzer/taint_svalue.h>
1818
#include <algorithm>
1919

2020

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+
2141
taint_svaluet::taint_svaluet(
2242
const taint_set_of_tokenst &in_tokens,
2343
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
2546
)
2647
: tokens(in_tokens)
2748
, vars(in_vars)
2849
, conds(in_conds.cbegin(),in_conds.cend())
50+
, suppressions(in_suppressions)
2951
{}
3052

3153
taint_svaluet::taint_svaluet()
3254
: tokens()
3355
, vars()
3456
, conds()
57+
, suppressions()
3558
{}
3659

3760
taint_svaluet::taint_svaluet(const taint_svaluet &other)
3861
: tokens(other.get_tokens())
3962
, vars(other.get_vars())
4063
, conds(other.get_conds().cbegin(),other.get_conds().cend())
64+
, suppressions(other.get_suppressions())
4165
{
4266
}
4367

@@ -54,16 +78,49 @@ void taint_svaluet::join(const taint_svaluet &other)
5478
vars.insert(other.get_vars().cbegin(),other.get_vars().cend());
5579
#endif
5680
conds.insert(other.get_conds().cbegin(),other.get_conds().cend());
81+
suppressions.insert(other.get_suppressions().cbegin(),
82+
other.get_suppressions().cend());
5783
}
5884

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+
59114
taint_condt::taint_condt(
60115
const std::vector<taint_tokent> &in_tested_symbols,
61116
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
63119
)
64120
: tested_symbols(in_tested_symbols)
65121
, conditionals(in_conditionals)
66122
, result(in_result)
123+
, suppression_ids(in_suppression_ids)
67124
{}
68125

69126

@@ -75,20 +132,21 @@ taint_svaluet taint_make_symbol()
75132

76133
taint_svaluet taint_make_symbol(const taint_symbolic_variablet svar)
77134
{
78-
return {{},{svar},{}};
135+
return {{},{svar},{},{}};
79136
}
80137

81138

82139
taint_svaluet taint_make_bottom()
83140
{
84-
return {{},{},{}};
141+
return {{},{},{},{}};
85142
}
86143

87144
bool equal(const taint_svaluet &a, const taint_svaluet &b)
88145
{
89146
return a.get_tokens() == b.get_tokens() &&
90147
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()
92150
;
93151
}
94152

@@ -120,6 +178,10 @@ bool proper_subset(const taint_svaluet &a, const taint_svaluet &b)
120178
if (b.get_conds().count(elem) == 0ULL)
121179
return false;
122180

181+
// TODO: this condition should be improved!
182+
if (!(a.get_suppressions() == b.get_suppressions()))
183+
return false;
184+
123185
return true;
124186
}
125187

@@ -130,15 +192,29 @@ taint_svaluet join(const taint_svaluet &a, const taint_svaluet &b)
130192
return result;
131193
}
132194

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+
133202

134203
bool operator==(const taint_condt &a, const taint_condt &b)
135204
{
136205
return a.get_tested_symbols() == b.get_tested_symbols() &&
137206
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()
139209
;
140210
}
141211

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+
}
142218

143219

144220
//taint_svaluet suppression(

0 commit comments

Comments
 (0)