21 #ifndef checkbufferoverrunH
22 #define checkbufferoverrunH
67 :
Check(myName(), tokenizer, settings, errorLogger) {}
83 c.
arrayIndexError(
nullptr, std::vector<Dimension>(), std::vector<ValueFlow::Value>());
85 c.
negativeIndexError(
nullptr, std::vector<Dimension>(), std::vector<ValueFlow::Value>());
101 void arrayIndexError(
const Token* tok,
102 const std::vector<Dimension>& dimensions,
103 const std::vector<ValueFlow::Value>& indexes);
104 void negativeIndexError(
const Token* tok,
105 const std::vector<Dimension>& dimensions,
106 const std::vector<ValueFlow::Value>& indexes);
108 void pointerArithmetic();
111 void bufferOverflow();
114 void arrayIndexThenCheck();
115 void arrayIndexThenCheckError(
const Token *tok,
const std::string &indexName);
117 void stringNotZeroTerminated();
118 void terminateStrncpyError(
const Token *tok,
const std::string &varname);
121 void argumentSizeError(
const Token *tok,
const std::string &functionName,
nonneg int paramIndex,
const std::string ¶mExpression,
const Variable *paramVar,
const Variable *functionArg);
123 void negativeArraySize();
124 void negativeArraySizeError(
const Token* tok);
138 static bool analyseWholeProgram1(
const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> &callsMap,
const CTU::FileInfo::UnsafeUsage &unsafeUsage,
int type,
ErrorLogger &errorLogger);
142 return "Bounds checking";
146 return "Out of bounds checking:\n"
147 "- Array index out of bounds\n"
148 "- Pointer arithmetic overflow\n"
149 "- Buffer overflow\n"
150 "- Dangerous usage of strncat()\n"
151 "- Using array index before checking it\n"
152 "- Partial string write that leads to buffer that is not zero terminated.\n"
153 "- Check for large enough arrays being passed to functions\n"
154 "- Allocating memory with a negative size\n";
buffer overruns and array index out of bounds
void arrayIndexThenCheckError(const Token *tok, const std::string &indexName)
std::string classInfo() const override
get information about this class, used to generate documentation
void stringNotZeroTerminated()
CheckBufferOverrun()
This constructor is used when registering the CheckClass.
CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
This constructor is used when running checks.
void negativeIndexError(const Token *tok, const std::vector< Dimension > &dimensions, const std::vector< ValueFlow::Value > &indexes)
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
run checks, the token list is not simplified
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override
get error messages
void pointerArithmeticError(const Token *tok, const Token *indexToken, const ValueFlow::Value *indexValue)
void negativeMemoryAllocationSizeError(const Token *tok, const ValueFlow::Value *value)
static std::string myName()
void arrayIndexError(const Token *tok, const std::vector< Dimension > &dimensions, const std::vector< ValueFlow::Value > &indexes)
void arrayIndexThenCheck()
void negativeArraySizeError(const Token *tok)
void argumentSizeError(const Token *tok, const std::string &functionName, nonneg int paramIndex, const std::string ¶mExpression, const Variable *paramVar, const Variable *functionArg)
void bufferOverflowError(const Token *tok, const ValueFlow::Value *value, Certainty certainty)
void objectIndexError(const Token *tok, const ValueFlow::Value *v, bool known)
Base class used for whole-program analysis.
Interface class that cppcheck uses to communicate with the checks.
virtual bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list< FileInfo * > &fileInfo, const Settings &, ErrorLogger &)
virtual FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const
virtual FileInfo * getFileInfo(const Tokenizer &, const Settings &) const
This is an interface, which the class responsible of error logging should implement.
This is just a container for general settings so that we don't need to pass individual values to func...
The token list that the TokenList generates is a linked-list of this class.
The main purpose is to tokenize the source code.
const Settings & getSettings() const
Information about a member variable.