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);
147 return (t.
id() == ID_pointer || t.
id() == ID_array) &&
158 const typet &buf_type,
187 for(goto_functionst::function_mapt::iterator
192 (*this)(it->second.body);
206 if(it->is_function_call())
216 const auto &arguments =
as_const(*target).call_arguments();
218 if(
function.
id()==ID_symbol)
223 if(identifier==
"strcoll")
226 else if(identifier==
"strncmp")
228 else if(identifier==
"strxfrm")
231 else if(identifier==
"strchr")
233 else if(identifier==
"strcspn")
236 else if(identifier==
"strpbrk")
239 else if(identifier==
"strrchr")
241 else if(identifier==
"strspn")
244 else if(identifier==
"strerror")
246 else if(identifier==
"strstr")
248 else if(identifier==
"strtok")
250 else if(identifier==
"sprintf")
252 else if(identifier==
"snprintf")
254 else if(identifier==
"fscanf")
267 if(arguments.size()<2)
270 "sprintf expected to have two or more arguments",
271 target->source_location());
280 assertion->source_location_nonconst().set_property_class(
"string");
281 assertion->source_location_nonconst().set_comment(
"sprintf buffer overflow");
293 target->turn_into_skip();
303 if(arguments.size()<3)
306 "snprintf expected to have three or more arguments",
307 target->source_location());
317 assertion->source_location_nonconst().set_property_class(
"string");
318 assertion->source_location_nonconst().set_comment(
"snprintf buffer overflow");
330 target->turn_into_skip();
340 if(arguments.size()<2)
343 "fscanf expected to have two or more arguments",
344 target->source_location());
359 target->turn_into_skip();
367 std::size_t format_string_inx,
368 std::size_t argument_start_inx,
369 const std::string &function_name)
371 const exprt &format_arg=arguments[format_string_inx];
374 format_arg.
id() == ID_address_of &&
386 for(
const auto &token : token_list)
390 const exprt &arg=arguments[argument_start_inx+args];
392 if(arg.
id()!=ID_string_constant)
396 if(arg.
type().
id() != ID_pointer)
405 assertion->source_location_nonconst().set_property_class(
"string");
406 std::string
comment(
"zero-termination of string argument of ");
408 assertion->source_location_nonconst().set_comment(
comment);
427 format_ass->source_location_nonconst().set_property_class(
"string");
428 format_ass->source_location_nonconst().set_comment(
429 "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 assertion->source_location_nonconst().set_property_class(
"string");
449 assertion->source_location_nonconst().set_comment(
450 "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;
527 assertion->source_location_nonconst().set_property_class(
"string");
528 std::string
comment(
"format string buffer overflow in ");
530 assertion->source_location_nonconst().set_comment(
comment);
534 dest, target, argument, arg_type, token.field_width);
550 const exprt &argument=arguments[argument_start_inx+args];
566 for(std::size_t i=argument_start_inx; i<arguments.size(); i++)
568 const typet &arg_type = arguments[i].type();
582 assertion->source_location_nonconst().set_property_class(
"string");
583 std::string
comment(
"format string buffer overflow in ");
585 assertion->source_location_nonconst().set_comment(
comment);
616 if(arguments.size()!=2)
619 "strchr expected to have two arguments", target->source_location());
626 assertion->source_location_nonconst().set_property_class(
"string");
627 assertion->source_location_nonconst().set_comment(
628 "zero-termination of string argument of strchr");
630 target->turn_into_skip();
640 if(arguments.size()!=2)
643 "strrchr expected to have two arguments", target->source_location());
650 assertion->source_location_nonconst().set_property_class(
"string");
651 assertion->source_location_nonconst().set_comment(
652 "zero-termination of string argument of strrchr");
654 target->turn_into_skip();
664 if(arguments.size()!=2)
667 "strstr expected to have two arguments", target->source_location());
674 assertion0->source_location_nonconst().set_property_class(
"string");
675 assertion0->source_location_nonconst().set_comment(
676 "zero-termination of 1st string argument of strstr");
680 assertion1->source_location_nonconst().set_property_class(
"string");
681 assertion1->source_location_nonconst().set_comment(
682 "zero-termination of 2nd string argument of strstr");
684 target->turn_into_skip();
694 if(arguments.size()!=2)
697 "strtok expected to have two arguments", target->source_location());
704 assertion0->source_location_nonconst().set_property_class(
"string");
705 assertion0->source_location_nonconst().set_comment(
706 "zero-termination of 1st string argument of strtok");
710 assertion1->source_location_nonconst().set_property_class(
"string");
711 assertion1->source_location_nonconst().set_comment(
712 "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=
"__strerror_buffer_size";
738 new_symbol_size.
name=identifier_size;
739 new_symbol_size.
mode=ID_C;
747 new_symbol_buf.
mode=ID_C;
748 new_symbol_buf.
type=type;
752 new_symbol_buf.
base_name=
"__strerror_buffer";
800 it->turn_into_skip();
808 const typet &buf_type,
811 irep_idt cntr_id=
"string_instrumentation::$counter";
818 new_symbol.
name=cntr_id;
819 new_symbol.
mode=ID_C;
840 if(buf_type.
id()==ID_pointer)
882 check->complete_goto(exit);
891 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)
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.
const type_with_subtypet & to_type_with_subtype(const typet &type)
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.
Thrown when we can't handle something in an input source file.
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
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())
void set(const irep_idt &name, const irep_idt &value)
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.
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.
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.
const typet & subtype() const
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 goto_instruction_codet representing an assignment in the program.
The Boolean constant true.
bitvector_typet c_index_type()
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)