Skip to content

Commit 539425d

Browse files
authored
Merge pull request diffblue#178 from diffblue/feature/SV_to_classes_in_symbol_table
SEC-12: Instrumentation of shadow vars as class members into symbols table.
2 parents 274fbb5 + c5c1b64 commit 539425d

File tree

3 files changed

+92
-15
lines changed

3 files changed

+92
-15
lines changed

src/taint-slicer/instrumenter.cpp

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
/// on instrumentation of data passed in "instrumentation_propst" instance.
1010

1111
#include <taint-slicer/instrumenter.h>
12+
#include <taint-slicer/irept_instrument.h>
1213
#include <util/msgstream.h>
1314

1415
std::string taint_prefix_of_instrumented_variable()
1516
{
16-
return "__CPROVER_TAINT_SLICER_INSTRUMENTED_TOKEN_";
17+
return "@__CPROVER_";
1718
}
1819

1920
static std::string convert_token_id_to_program_identifier(
@@ -38,20 +39,61 @@ static std::string generate_fresh_automaton_variable_for_token(
3839
return var_name;
3940
}
4041

42+
static irept add_shadow_variables_to_type(
43+
const irept &type,
44+
const std::vector<taint_instrumentert::automaton_variable_idt> &vars,
45+
const taint_datatype_infot &info)
46+
{
47+
if(type.id()==ID_struct)
48+
{
49+
const struct_typet &struct_type=
50+
to_struct_type(static_cast<const typet &>(type));
51+
const auto tag="java::"+as_string(struct_type.get_tag());
52+
if(tag==info.get_id())
53+
{
54+
if(info.subclass_required())
55+
{
56+
// TODO!
57+
}
58+
else
59+
{
60+
struct_typet result=struct_type;
61+
struct_typet::componentst &components=result.components();
62+
for(const taint_instrumentert::automaton_variable_idt &var : vars)
63+
{
64+
components.push_back(struct_typet::componentt{
65+
var, bool_typet() });
66+
components.back().set_pretty_name(var);
67+
components.back().set_access(ID_public);
68+
}
69+
return result;
70+
}
71+
}
72+
}
73+
return type;
74+
}
75+
4176
taint_instrumentert::taint_instrumentert(
42-
const taint_instrumentation_propst &props,
77+
const taint_instrumentation_propst &in_props,
4378
const taint_programt *const in_program,
4479
taint_statisticst *const in_statistics,
4580
const bool use_data_flow_insensitive_instrumentation)
46-
: program(in_program)
81+
: props(in_props)
82+
, program(in_program)
4783
, statistics(in_statistics)
4884
, use_data_flow_insensitive_version(use_data_flow_insensitive_instrumentation)
4985
{
50-
// The next line must be here in order to prevent clang produce the error:
51-
// `error: private field 'use_data_flow_insensitive_version' is not used
52-
// [-Werror,-Wunused-private-field]`
53-
(void)use_data_flow_insensitive_version;
86+
}
5487

88+
/// Builds a new symbol table from the original symbol
89+
/// table in in_program->get_symbol_table(), by removing of symbols not related
90+
/// to the set of functions defined in the passed instrumentation properties.
91+
/// The function also build a new set of functions from those defined in
92+
/// in_program->get_functions() and which appear in props.get_location_props().
93+
/// These functions are instrumented by a new code accodring to recipes in
94+
/// individual elements of props.get_location_props().
95+
void taint_instrumentert::run()
96+
{
5597
assert(program!=nullptr);
5698
assert(statistics!=nullptr);
5799

@@ -129,6 +171,13 @@ taint_instrumentert::taint_instrumentert(
129171
instr.type=ASSUME;
130172
}
131173

174+
if(!use_data_flow_insensitive_version)
175+
{
176+
// Now we introduce shadow variables as members of (1) existing types
177+
// and (2) newly created types (for basic types).
178+
instrument_data_types(props);
179+
}
180+
132181
// We have to change the way how we identify instrumentation locations.
133182
// Namely, instead of using iterators for referencing instructions we have to
134183
// switch to distances from the first instruction. This is because we operate
@@ -182,6 +231,32 @@ taint_instrumentert::taint_instrumentert(
182231
statistics=nullptr;
183232
}
184233

234+
void taint_instrumentert::instrument_data_types(
235+
const taint_instrumentation_propst &props)
236+
{
237+
std::set<irep_idt> new_type_names;
238+
for(const auto &id_info : props.get_datatypes())
239+
{
240+
std::vector<automaton_variable_idt> vars;
241+
for(const auto &token : id_info.second.get_tokens())
242+
vars.push_back(from_tokens_to_vars.at(token));
243+
if(id_info.second.subclass_required())
244+
{
245+
// TODO!
246+
}
247+
else
248+
{
249+
symbolt &symbol=instrumented_symbol_table.lookup(id_info.first);
250+
const irept itype=instrument(symbol.type, std::bind(
251+
&add_shadow_variables_to_type,
252+
std::placeholders::_1,
253+
std::cref(vars),
254+
std::cref(id_info.second)));
255+
symbol.type=static_cast<const typet&>(itype);
256+
}
257+
}
258+
}
259+
185260
std::size_t taint_instrumentert::instrument_location(
186261
const taint_instrumentation_propst::location_props_idt lid,
187262
const std::size_t instruction_index,

src/taint-slicer/instrumenter.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ class taint_instrumentert
4040
4141
Outputs:
4242
43-
Purpose: The function builds a new symbol table from the original symbol
44-
table in _program->get_symbol_table(), by removing of symbols not related
45-
to the set of functions defined in the passed instrumentation properties.
46-
The function also build a new set of function from those defined in
47-
_program->get_functions() and which appear in props.get_location_props().
48-
These functions are instrumented by a new code accodring to recipes in
49-
individual elements of props.get_location_props().
43+
Purpose:
5044
5145
\*******************************************************************/
5246
taint_instrumentert(
@@ -55,6 +49,8 @@ class taint_instrumentert
5549
taint_statisticst * const in_statistics,
5650
const bool use_data_flow_insensitive_instrumentation);
5751

52+
void run();
53+
5854
const goto_functionst &get_instrumented_functions() const
5955
{ return instrumented_functions; }
6056

@@ -66,6 +62,8 @@ class taint_instrumentert
6662

6763
private:
6864

65+
void instrument_data_types(const taint_instrumentation_propst &props);
66+
6967
/*******************************************************************\
7068
7169
Function: instrument_location
@@ -87,6 +85,7 @@ class taint_instrumentert
8785
const std::size_t instruction_index,
8886
const taint_instrumentation_propst &props);
8987

88+
const taint_instrumentation_propst &props;
9089
const taint_programt *program;
9190
taint_statisticst *statistics;
9291
goto_functionst instrumented_functions;

src/taint-slicer/slicer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ void taint_slicert::compute_slice(
9797
std::vector<taint_slicing_taskt> sliced_goto_programs;
9898
for(std::size_t i=0UL, n=instrumentation_props.size(); i!=n; ++i)
9999
{
100-
const taint_instrumentert instrumenter(
100+
taint_instrumentert instrumenter(
101101
instrumentation_props.at(i),
102102
program,
103103
statistics,
104104
use_data_flow_insensitive_instrumentation);
105+
106+
instrumenter.run();
107+
105108
const std::pair<taint_slicing_taskt,std::string> task_valid=
106109
build_slicing_task(
107110
instrumentation_props.at(i),

0 commit comments

Comments
 (0)