Skip to content

Commit ea39c74

Browse files
NathanJPhillipssmowton
authored andcommitted
Merge pull request diffblue#117 from trtikm/cleanup/general-tidy-and-fix
Cleanup/general tidy and fix
1 parent 0bc430c commit ea39c74

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

src/goto-analyzer/taint_rules.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ boost::optional<taint_rulet::tainted_locationt> taint_rulet::tainted_locationt::
115115
return boost::none;
116116
}
117117
taint_tokent token = taint_tokent::fresh();
118-
tokens.insert(named_tokenst::value_type(taint_string, token));
118+
tokens.left.insert({ taint_string, token });
119119
return tainted_locationt(location, token, json["dereference"].is_true());
120120
}
121121

@@ -140,7 +140,7 @@ std::unique_ptr<taint_rulet> taint_rulet::load(
140140
tainted_locationt::load(input_json, tokens, message_handler);
141141
return std::unique_ptr<taint_rulet>(new taint_rulet(input, *input /* TODO */));
142142
}
143-
else
143+
else if(is_sink_json.is_false() || is_sink_json.is_null())
144144
{
145145
boost::optional<tainted_locationt> input =
146146
tainted_locationt::load(input_json, tokens, message_handler),
@@ -155,6 +155,13 @@ std::unique_ptr<taint_rulet> taint_rulet::load(
155155
}
156156
return std::unique_ptr<taint_rulet>(new taint_rulet(input, *result));
157157
}
158+
else
159+
{
160+
msg.error()
161+
<< "Rule has isSink that is not true or false, ignoring it."
162+
<< messaget::eom;
163+
return nullptr;
164+
}
158165
}
159166

160167
std::unique_ptr<taint_rulest> taint_rulest::load(
@@ -172,7 +179,6 @@ std::unique_ptr<taint_rulest> taint_rulest::load(
172179
}
173180

174181
std::unique_ptr<taint_rulest> rules(new taint_rulest());
175-
named_tokenst tokens;
176182
for(const jsont &rule_json : root.array)
177183
{
178184
if(!rule_json.is_object())
@@ -204,10 +210,11 @@ std::unique_ptr<taint_rulest> taint_rulest::load(
204210
// names (without packages).
205211
const std::string method_name = method_json.value;
206212

207-
std::unique_ptr<taint_rulet> rule = taint_rulet::load(rule_json, tokens, message_handler);
213+
std::unique_ptr<taint_rulet> rule =
214+
taint_rulet::load(rule_json, rules->named_tokens, message_handler);
208215
if(rule != nullptr)
209216
// TODO: Convert base_class_name to symbol_exprt
210-
rules->add(symbol_exprt(), move(rule));
217+
rules->add(irep_idt(), move(rule));
211218
}
212219

213220
return rules->empty() ? nullptr : move(rules);

src/goto-analyzer/taint_rules.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ class taint_rulet
104104
files.
105105
106106
\*******************************************************************/
107-
class taint_rulest : private std::map<symbol_exprt, std::shared_ptr<taint_rulet>>
107+
class taint_rulest : private std::map<irep_idt, std::shared_ptr<taint_rulet>>
108108
{
109+
private:
110+
named_tokenst named_tokens;
109111
public:
110112

111113
/*******************************************************************\
@@ -122,9 +124,9 @@ class taint_rulest : private std::map<symbol_exprt, std::shared_ptr<taint_rulet>
122124
Adds a rule to the set.
123125
124126
\*******************************************************************/
125-
void add(symbol_exprt function, std::shared_ptr<taint_rulet> rule)
127+
void add(const irep_idt &fn_name, std::shared_ptr<taint_rulet> rule)
126128
{
127-
insert({ function, rule });
129+
insert({ fn_name, rule });
128130
}
129131

130132

@@ -148,10 +150,14 @@ class taint_rulest : private std::map<symbol_exprt, std::shared_ptr<taint_rulet>
148150
Purpose:
149151
150152
\*******************************************************************/
151-
std::shared_ptr<taint_rulet> find(const symbol_exprt &function) const
153+
std::shared_ptr<taint_rulet> find(const irep_idt &fn_name) const
152154
{
155+
// We currently match directly on the name
156+
// TODO: Search for any methods derived on base classes of the class name
157+
// used in the call
158+
// class_hierarchyt::idst parents = class_hierarchy.get_parents_trans(class_id);
153159
const_iterator it =
154-
std::map<symbol_exprt, std::shared_ptr<taint_rulet>>::find(function);
160+
std::map<irep_idt, std::shared_ptr<taint_rulet>>::find(fn_name);
155161
return it == end() ? nullptr : it->second;
156162
}
157163

src/goto-analyzer/taint_summary.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ static void initialise_domain(
126126
else if (it->type == FUNCTION_CALL)
127127
{
128128
code_function_callt const& fn_call = to_code_function_call(it->code);
129-
if (fn_call.function().id() == ID_symbol)
129+
const exprt &callee_expr = fn_call.function();
130+
if (callee_expr.id() == ID_symbol)
130131
{
131-
std::string const callee_ident =
132-
as_string(to_symbol_expr(fn_call.function()).get_identifier());
133-
134-
auto const& fn_type = functions_map.at(callee_ident).type;
132+
irep_idt callee_id = to_symbol_expr(callee_expr).get_identifier();
133+
const std::string callee_ident = as_string(callee_id);
134+
const code_typet &fn_type = functions_map.at(callee_id).type;
135135

136136
taint_summary_ptrt const summary =
137137
database.find<taint_summaryt>(callee_ident);
@@ -390,9 +390,6 @@ static void build_symbols_substitution(
390390
namespace_utilst nsu(ns);
391391
auto parameter_indices=get_parameter_indices(fn_type);
392392

393-
std::string const callee_ident =
394-
as_string(to_symbol_expr(fn_call.function()).get_identifier());
395-
396393
for (const std::pair<taint_lvaluet, taint_sett>& lvalue_taint : summary->input())
397394
{
398395
assert(!lvalue_taint.second.is_bottom());
@@ -947,20 +944,19 @@ numbered_lvalue_to_taint_mapt transform(
947944
case FUNCTION_CALL:
948945
{
949946
const code_function_callt &fn_call = to_code_function_call(I.code);
950-
if (fn_call.function().id() == ID_symbol)
947+
const exprt &callee_expr = fn_call.function();
948+
if (callee_expr.id() == ID_symbol)
951949
{
952950
msg.debug() << "Recognised FUNCTION_CALL instruction." << messaget::eom;
953951

954-
const std::string callee_ident =
955-
as_string(to_symbol_expr(fn_call.function()).get_identifier());
956-
957-
const code_typet &fn_type = functions_map.at(callee_ident).type;
952+
irep_idt callee_id = to_symbol_expr(callee_expr).get_identifier();
953+
const std::string callee_ident = as_string(callee_id);
954+
const code_typet &fn_type = functions_map.at(callee_id).type;
958955

959956
assert(lvsa != nullptr);
960957
// Find a matching rule
961958
taint_rulest taint_rules;
962-
std::shared_ptr<taint_rulet> taint_rule =
963-
taint_rules.find(to_symbol_expr(fn_call.function()));
959+
std::shared_ptr<taint_rulet> taint_rule = taint_rules.find(callee_id);
964960
// Find the summary
965961
taint_summary_ptrt const summary =
966962
database.find<taint_summaryt>(callee_ident);
@@ -1057,7 +1053,7 @@ numbered_lvalue_to_taint_mapt transform(
10571053
summary->output(),
10581054
symbols_substitution,
10591055
caller_ident,
1060-
callee_ident,
1056+
callee_id,
10611057
fn_call,
10621058
fn_type,
10631059
ns,
@@ -1069,19 +1065,19 @@ numbered_lvalue_to_taint_mapt transform(
10691065
else
10701066
{
10711067
msg.warning()
1072-
<< "!!! WARNING !!! : No summary and no transition rule was "
1073-
"found for the called function "
1074-
<< as_string(callee_ident)
1075-
<< "So, we use identity as a transformation function."
1068+
<< "!!! WARNING !!! : No summary was found for the called function "
1069+
<< callee_ident
1070+
<< "Identity will be used as a transformation function."
10761071
<< messaget::eom;
10771072
}
10781073
}
10791074
else
10801075
msg.warning()
1081-
<< "!!! WARNING !!! : Recognised FUNCTION_CALL instruction "
1082-
"using non-identifier call expression. Such call is not "
1083-
"supported. So, we use identity as a transformation "
1084-
"function." << messaget::eom;
1076+
<< "!!! WARNING !!! : Recognised FUNCTION_CALL instruction using a "
1077+
"non-identifier call expression. All such calls should have been "
1078+
"removed by the remove-function-pointers pass."
1079+
"Identity will be used as a transformation function."
1080+
<< messaget::eom;
10851081
}
10861082
break;
10871083
case OTHER:

0 commit comments

Comments
 (0)