Go to the documentation of this file.
31 result.copy_to_operands(what);
32 result.
set(
"lhs", write);
42 result.
set(
"lhs", write);
133 std::size_t format_string_inx,
134 std::size_t argument_start_inx,
135 const std::string &function_name);
141 std::size_t format_string_inx,
142 std::size_t argument_start_inx,
143 const std::string &function_name);
148 (t.
id()==ID_pointer || t.
id()==ID_array) &&
157 const typet &buf_type,
186 for(goto_functionst::function_mapt::iterator
191 (*this)(it->second.body);
205 if(it->is_function_call())
215 const auto &arguments =
as_const(*target).call_arguments();
217 if(
function.
id()==ID_symbol)
222 if(identifier==
"strcoll")
225 else if(identifier==
"strncmp")
227 else if(identifier==
"strxfrm")
230 else if(identifier==
"strchr")
232 else if(identifier==
"strcspn")
235 else if(identifier==
"strpbrk")
238 else if(identifier==
"strrchr")
240 else if(identifier==
"strspn")
243 else if(identifier==
"strerror")
245 else if(identifier==
"strstr")
247 else if(identifier==
"strtok")
249 else if(identifier==
"sprintf")
251 else if(identifier==
"snprintf")
253 else if(identifier==
"fscanf")
266 if(arguments.size()<2)
269 "sprintf expected to have two or more arguments",
270 target->source_location);
279 assertion->source_location.set_property_class(
"string");
280 assertion->source_location.set_comment(
"sprintf buffer overflow");
291 target->turn_into_skip();
301 if(arguments.size()<3)
304 "snprintf expected to have three or more arguments",
305 target->source_location);
315 assertion->source_location.set_property_class(
"string");
316 assertion->source_location.set_comment(
"snprintf buffer overflow");
327 target->turn_into_skip();
337 if(arguments.size()<2)
340 "fscanf expected to have two or more arguments", target->source_location);
354 target->turn_into_skip();
362 std::size_t format_string_inx,
363 std::size_t argument_start_inx,
364 const std::string &function_name)
366 const exprt &format_arg=arguments[format_string_inx];
369 format_arg.
id() == ID_address_of &&
381 for(
const auto &token : token_list)
385 const exprt &arg=arguments[argument_start_inx+args];
387 if(arg.
id()!=ID_string_constant)
391 if(arg.
type().
id() != ID_pointer)
400 assertion->source_location.set_property_class(
"string");
401 std::string
comment(
"zero-termination of string argument of ");
403 assertion->source_location.set_comment(
comment);
422 format_ass->source_location.set_property_class(
"string");
423 format_ass->source_location.set_comment(
424 "zero-termination of format string of " + function_name);
426 for(std::size_t i=2; i<arguments.size(); i++)
428 const exprt &arg=arguments[i];
434 if(arg.
type().
id() != ID_pointer)
443 assertion->source_location.set_property_class(
"string");
444 assertion->source_location.set_comment(
445 "zero-termination of string argument of " + function_name);
455 std::size_t format_string_inx,
456 std::size_t argument_start_inx,
457 const std::string &function_name)
459 const exprt &format_arg=arguments[format_string_inx];
462 format_arg.
id() == ID_address_of &&
474 for(
const auto &token : token_list)
487 const exprt &argument=arguments[argument_start_inx+args];
492 if(token.field_width!=0)
500 if(arg_type.
id()==ID_pointer)
511 condition = fw_lt_bs;
521 assertion->source_location.set_property_class(
"string");
522 std::string
comment(
"format string buffer overflow in ");
524 assertion->source_location.set_comment(
comment);
528 dest, target, argument, arg_type, token.field_width);
544 const exprt &argument=arguments[argument_start_inx+args];
560 for(std::size_t i=argument_start_inx; i<arguments.size(); i++)
562 const typet &arg_type = arguments[i].type();
576 assertion->source_location.set_property_class(
"string");
577 std::string
comment(
"format string buffer overflow in ");
579 assertion->source_location.set_comment(
comment);
610 if(arguments.size()!=2)
613 "strchr expected to have two arguments", target->source_location);
620 assertion->source_location.set_property_class(
"string");
621 assertion->source_location.set_comment(
622 "zero-termination of string argument of strchr");
624 target->turn_into_skip();
634 if(arguments.size()!=2)
637 "strrchr expected to have two arguments", target->source_location);
644 assertion->source_location.set_property_class(
"string");
645 assertion->source_location.set_comment(
646 "zero-termination of string argument of strrchr");
648 target->turn_into_skip();
658 if(arguments.size()!=2)
661 "strstr expected to have two arguments", target->source_location);
668 assertion0->source_location.set_property_class(
"string");
669 assertion0->source_location.set_comment(
670 "zero-termination of 1st string argument of strstr");
674 assertion1->source_location.set_property_class(
"string");
675 assertion1->source_location.set_comment(
676 "zero-termination of 2nd string argument of strstr");
678 target->turn_into_skip();
688 if(arguments.size()!=2)
691 "strtok expected to have two arguments", target->source_location);
698 assertion0->source_location.set_property_class(
"string");
699 assertion0->source_location.set_comment(
700 "zero-termination of 1st string argument of strtok");
704 assertion1->source_location.set_property_class(
"string");
705 assertion1->source_location.set_comment(
706 "zero-termination of 2nd string argument of strtok");
708 target->turn_into_skip();
720 it->turn_into_skip();
724 irep_idt identifier_buf=
"__strerror_buffer";
725 irep_idt identifier_size=
"__strerror_buffer_size";
730 new_symbol_size.
base_name=
"__strerror_buffer_size";
732 new_symbol_size.
name=identifier_size;
733 new_symbol_size.
mode=ID_C;
741 new_symbol_buf.
mode=ID_C;
742 new_symbol_buf.
type=type;
746 new_symbol_buf.
base_name=
"__strerror_buffer";
796 it->turn_into_skip();
804 const typet &buf_type,
807 irep_idt cntr_id=
"string_instrumentation::$counter";
814 new_symbol.
name=cntr_id;
815 new_symbol.
mode=ID_C;
836 if(buf_type.
id()==ID_pointer)
876 check->complete_goto(exit);
884 invalidate->code_nonconst() =
code_assignt(deref, nondet);
#define Forall_goto_program_instructions(it, program)
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
void do_snprintf(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
void do_strtok(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
const typet & subtype() const
void operator()(goto_programt &dest)
The type of an expression, extends irept.
void do_strchr(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
void do_format_string_write(goto_programt &dest, goto_programt::const_targett target, const code_function_callt::argumentst &arguments, std::size_t format_string_inx, std::size_t argument_start_inx, const std::string &function_name)
exprt is_zero_string(const exprt &what, bool write)
typet type
Type of symbol.
Operator to dereference a pointer.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
void instrument(goto_programt &dest, goto_programt::targett it)
const string_constantt & to_string_constant(const exprt &expr)
targett add(instructiont &&instruction)
Adds a given instruction at the end.
The plus expression Associativity is not specified.
symbol_tablet & symbol_table
Base class for all expressions.
Generic base class for unary expressions.
irep_idt base_name
Base (non-scoped) name.
void do_strncmp(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt::operandst &arguments)
void do_strstr(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
void do_format_string_read(goto_programt &dest, goto_programt::const_targett target, const code_function_callt::argumentst &arguments, std::size_t format_string_inx, std::size_t argument_start_inx, const std::string &function_name)
struct configt::ansi_ct ansi_c
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
function_mapt function_map
bitvector_typet index_type()
string_instrumentationt(symbol_tablet &_symbol_table)
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_goto(targett _target, const source_locationt &l=source_locationt::nil())
irep_idt pretty_name
Language-specific display name.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
void do_strerror(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt::operandst &arguments)
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
irep_idt mode
Language mode.
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
void string_instrumentation(symbol_tablet &symbol_table, goto_programt &dest)
const std::string & id2string(const irep_idt &d)
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
exprt zero_string_length(const exprt &what, bool write)
const source_locationt & source_location() const
const irep_idt & get_identifier() const
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
API to expression classes for Pointers.
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
unsignedbv_typet unsigned_int_type()
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
std::vector< exprt > operandst
exprt::operandst argumentst
void do_sprintf(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
The Boolean constant false.
bitvector_typet char_type()
std::size_t get_width() const
A side_effect_exprt that returns a non-deterministically chosen value.
void invalidate_buffer(goto_programt &dest, goto_programt::const_targett target, const exprt &buffer, const typet &buf_type, const mp_integer &limit)
A collection of goto functions.
goto_functionst goto_functions
GOTO functions.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
void set(const irep_namet &name, const irep_idt &value)
const symbolst & symbols
Read-only field, used to look up symbols given their names.
A base class for relations, i.e., binary predicates whose two operands have the same type.
bool is_string_type(const typet &t) const
void do_function_call(goto_programt &dest, goto_programt::targett target)
A generic container class for the GOTO intermediate representation of one function.
exprt buffer_size(const exprt &what)
instructionst::const_iterator const_targett
const irept & get_nil_irep()
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
Operator to return the address of an object.
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
Semantic type conversion.
unsignedbv_typet size_type()
void do_strrchr(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
A codet representing an assignment in the program.
The Boolean constant true.
static std::string comment(const rw_set_baset::entryt &entry, bool write)
This class represents an instruction in the GOTO intermediate representation.
const source_locationt & source_location() const
symbol_tablet symbol_table
Symbol table.
irep_idt name
The unique identifier.
instructionst::iterator targett
void do_strcat(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt::operandst &arguments)
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
void make_type(exprt &dest, const typet &type)
Data structure for representing an arbitrary statement in a program.
void do_fscanf(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)