30 result.copy_to_operands(what);
31 result.
set(
"lhs", write);
41 result.
set(
"lhs", write);
132 std::size_t format_string_inx,
133 std::size_t argument_start_inx,
134 const std::string &function_name);
140 std::size_t format_string_inx,
141 std::size_t argument_start_inx,
142 const std::string &function_name);
146 return (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" || identifier ==
"__isoc99_fscanf")
266 if(arguments.size()<2)
269 "sprintf expected to have two or more arguments",
270 target->source_location());
279 annotated_location.
set_comment(
"sprintf buffer overflow");
292 target->turn_into_skip();
302 if(arguments.size()<3)
305 "snprintf expected to have three or more arguments",
306 target->source_location());
315 annotated_location.
set_comment(
"snprintf buffer overflow");
329 target->turn_into_skip();
339 if(arguments.size()<2)
342 "fscanf expected to have two or more arguments",
343 target->source_location());
358 target->turn_into_skip();
366 std::size_t format_string_inx,
367 std::size_t argument_start_inx,
368 const std::string &function_name)
370 const exprt &format_arg=arguments[format_string_inx];
373 format_arg.
id() == ID_address_of &&
385 for(
const auto &token : token_list)
389 const exprt &arg=arguments[argument_start_inx+args];
391 if(arg.
id()!=ID_string_constant)
395 if(arg.
type().
id() != ID_pointer)
403 std::string
comment(
"zero-termination of string argument of ");
427 "zero-termination of format string of " + function_name);
431 for(std::size_t i=2; i<arguments.size(); i++)
433 const exprt &arg=arguments[i];
439 if(arg.
type().
id() != ID_pointer)
448 "zero-termination of string argument of " + function_name);
460 std::size_t format_string_inx,
461 std::size_t argument_start_inx,
462 const std::string &function_name)
464 const exprt &format_arg=arguments[format_string_inx];
467 format_arg.
id() == ID_address_of &&
479 for(
const auto &token : token_list)
492 const exprt &argument=arguments[argument_start_inx+args];
497 if(token.field_width!=0)
505 if(arg_type.
id()==ID_pointer)
516 condition = fw_lt_bs;
526 std::string
comment(
"format string buffer overflow in ");
534 dest, target, argument, arg_type, token.field_width);
550 const exprt &argument=arguments[argument_start_inx+args];
556 lhs, rhs, target->source_location()));
566 for(std::size_t i=argument_start_inx; i<arguments.size(); i++)
568 const typet &arg_type = arguments[i].type();
581 std::string
comment(
"format string buffer overflow in ");
616 if(arguments.size()!=2)
619 "strchr expected to have two arguments", target->source_location());
625 "zero-termination of string argument of strchr");
629 target->turn_into_skip();
639 if(arguments.size()!=2)
642 "strrchr expected to have two arguments", target->source_location());
648 "zero-termination of string argument of strrchr");
652 target->turn_into_skip();
662 if(arguments.size()!=2)
665 "strstr expected to have two arguments", target->source_location());
673 "zero-termination of 1st string argument of strstr");
679 "zero-termination of 2nd string argument of strstr");
683 target->turn_into_skip();
693 if(arguments.size()!=2)
696 "strtok expected to have two arguments", target->source_location());
704 "zero-termination of 1st string argument of strtok");
710 "zero-termination of 2nd string argument of strtok");
714 target->turn_into_skip();
726 it->turn_into_skip();
730 irep_idt identifier_buf=
"__strerror_buffer";
731 irep_idt identifier_size=
"__strerror_buffer_size";
736 new_symbol_size.base_name = identifier_size;
737 new_symbol_size.pretty_name=new_symbol_size.base_name;
738 new_symbol_size.is_state_var=
true;
739 new_symbol_size.is_lvalue=
true;
740 new_symbol_size.is_static_lifetime=
true;
743 symbolt new_symbol_buf{identifier_buf, type, ID_C};
744 new_symbol_buf.is_state_var=
true;
745 new_symbol_buf.is_lvalue=
true;
746 new_symbol_buf.is_static_lifetime=
true;
747 new_symbol_buf.base_name = identifier_buf;
748 new_symbol_buf.pretty_name=new_symbol_buf.base_name;
764 it->source_location()));
771 it->source_location()));
784 it->source_location()));
794 it->turn_into_skip();
802 const typet &buf_type,
805 irep_idt cntr_id=
"string_instrumentation::$counter";
810 new_symbol.base_name=
"$counter";
811 new_symbol.pretty_name=new_symbol.base_name;
812 new_symbol.is_state_var=
true;
813 new_symbol.is_lvalue=
true;
814 new_symbol.is_static_lifetime=
true;
827 target->source_location()));
831 if(buf_type.
id()==ID_pointer)
869 cntr_sym.
symbol_expr(), plus, target->source_location()));
877 check->complete_goto(exit);
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
unsignedbv_typet unsigned_int_type()
unsignedbv_typet size_type()
bitvector_typet char_type()
bitvector_typet c_index_type()
Operator to return the address of an object.
A base class for relations, i.e., binary predicates whose two operands have the same type.
std::size_t get_width() const
A goto_instruction_codet representing an assignment in the program.
exprt::operandst argumentst
struct configt::ansi_ct ansi_c
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
std::vector< exprt > operandst
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
typet & type()
Return the type of the expression.
The Boolean constant false.
A collection of goto functions.
function_mapt function_map
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
This class represents an instruction in the GOTO intermediate representation.
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
instructionst::iterator targett
instructionst::const_iterator const_targett
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_goto(targett _target, const source_locationt &l=source_locationt::nil())
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
Thrown when we can't handle something in an input source file.
void set(const irep_idt &name, const irep_idt &value)
const irep_idt & id() const
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
The plus expression Associativity is not specified.
A side_effect_exprt that returns a non-deterministically chosen value.
void set_comment(const irep_idt &comment)
void set_property_class(const irep_idt &property_class)
void do_strtok(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
void do_function_call(goto_programt &dest, goto_programt::targett target)
bool is_string_type(const typet &t) const
void operator()(goto_programt &dest)
void do_snprintf(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
string_instrumentationt(symbol_table_baset &_symbol_table)
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)
symbol_table_baset & symbol_table
void do_strncmp(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt::operandst &arguments)
void make_type(exprt &dest, const typet &type)
void do_sprintf(goto_programt &dest, goto_programt::targett target, 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_strerror(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt::operandst &arguments)
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)
void do_fscanf(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
void instrument(goto_programt &dest, goto_programt::targett it)
void do_strcat(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt::operandst &arguments)
void do_strrchr(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
void invalidate_buffer(goto_programt &dest, goto_programt::const_targett target, const exprt &buffer, const typet &buf_type, const mp_integer &limit)
void do_strchr(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt::operandst &arguments)
const irep_idt & get_identifier() const
The symbol table base class interface.
virtual std::pair< symbolt &, bool > insert(symbolt symbol)=0
Move or copy a new symbol to the symbol table.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
The Boolean constant true.
const typet & subtype() const
Semantic type conversion.
The type of an expression, extends irept.
Generic base class for unary expressions.
#define Forall_goto_program_instructions(it, program)
const std::string & id2string(const irep_idt &d)
API to expression classes for Pointers.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
static std::string comment(const rw_set_baset::entryt &entry, bool write)
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const string_constantt & to_string_constant(const exprt &expr)
void string_instrumentation(symbol_table_baset &symbol_table, goto_programt &dest)
exprt buffer_size(const exprt &what)
exprt is_zero_string(const exprt &what, bool write)
exprt zero_string_length(const exprt &what, bool write)
const type_with_subtypet & to_type_with_subtype(const typet &type)