ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
goto_check_unchecked_return Class Reference

Detect uses of a fallible call's return value that are not first constrained to the call's success domain (CWE-252, "Unchecked Return Value"). More...

#include <goto_check_unchecked_return.h>

Inheritance diagram for goto_check_unchecked_return:
[legend]

Public Member Functions

 goto_check_unchecked_return (contextt &context)
Public Member Functions inherited from goto_functions_algorithm
 goto_functions_algorithm (bool sideffect)
unsigned get_number_of_functions ()
unsigned get_number_of_loops ()
bool run (goto_functionst &) override
 Executes the algorithm over a T object.
void setTarget (const std::string &_tgt)
Public Member Functions inherited from algorithm< goto_functionst >
 algorithm (bool sideeffect)
virtual ~algorithm ()=default
bool has_sideeffect ()
 Says wether the algorithm is a plain analysis or if it also changes the structure.

Protected Member Functions

bool runOnFunction (std::pair< const irep_idt, goto_functiont > &F) override
Protected Member Functions inherited from goto_functions_algorithm
virtual bool runOnLoop (loopst &loop, goto_programt &goto_program)
virtual bool runOnProgram (goto_functionst &)

Protected Attributes

contextt & context
Protected Attributes inherited from goto_functions_algorithm
std::string target_function = ""
Protected Attributes inherited from algorithm< goto_functionst >
const bool sideeffect

Detailed Description

Detect uses of a fallible call's return value that are not first constrained to the call's success domain (CWE-252, "Unchecked Return Value").

For every FUNCTION_CALL r = f(...) whose callee f is on the fixed whitelist in <util/fallible_calls.h>, the pass scans forward over the containing function's goto-program tracking r (and any propagation chain r' = (cast)? r). The chain ends when the tracked variable appears in:

  • a GOTO guard or __ESBMC_assume guard — the use is path-narrowing, leave it alone;
  • any other read position (RHS of ASSIGN, function-call argument, dereference target, RETURN value, ASSERT guard, OTHER such as FREE) — insert an ASSERT(success_pred(tracked)) immediately before that instruction, with comment unchecked return value of <fn>: <r> and property unchecked-return-value;
  • a re-assignment to a non-propagation right-hand side — the binding is dead, stop silently.

v1 limitations (documented for follow-up issues):

  • intra-procedural only;
  • only direct-symbol callees and direct-symbol return values are considered; calls that discard the return (pthread_mutex_lock(&m); with no LHS) are skipped — flagging them needs a synthesised binding;
  • the propagation chain is a single alias hop (tmp → user-visible binding); after the first user-visible assignment, the synthetic temporary is no longer tracked, so a second indirection (q = p; *p = 1;) misses the use of p;
  • malloc and realloc are lowered to side-effect expressions by the Clang frontend and are not reached by this pass — unchecked uses of their results are already caught as CWE-476;
  • operational models that hard-code a return value (e.g. pthread_mutex_lock_noassert always returns 0) make the inserted assertion vacuously true; the check is meaningful only for callees whose OM leaves the return nondet.

Runs as a preprocessing algorithm, mirroring goto_check_uninit_vars.

Constructor & Destructor Documentation

◆ goto_check_unchecked_return()

goto_check_unchecked_return::goto_check_unchecked_return ( contextt & context)
inlineexplicit

Member Function Documentation

◆ runOnFunction()

bool goto_check_unchecked_return::runOnFunction ( std::pair< const irep_idt, goto_functiont > & F)
overrideprotectedvirtual

Reimplemented from goto_functions_algorithm.

Member Data Documentation

◆ context

contextt& goto_check_unchecked_return::context
protected

The documentation for this class was generated from the following files: