47 if (!SVFUtil::isa<CallICFGNode>(node))
118 std::string funcName =
callNode->getCalledFunction()->getName();
119 if (funcName ==
"SAFE_BUFACCESS")
133 assert(
false &&
"SAFE_BUFACCESS size is bottom");
140 <<
" — " <<
callNode->toString() <<
"\n";
146 <<
" — Position: " <<
callNode->getSourceLoc() <<
"\n";
150 else if (funcName ==
"UNSAFE_BUFACCESS")
154 if (
callNode->arg_size() < 2)
return;
160 assert(
false &&
"UNSAFE_BUFACCESS size is bottom");
167 <<
" — " <<
callNode->toString() <<
"\n";
173 <<
" — Position: " <<
callNode->getSourceLoc() <<
"\n";
229 if (
annotation.find(
"MEMCPY") != std::string::npos)
231 if (
annotation.find(
"MEMSET") != std::string::npos)
233 if (
annotation.find(
"STRCPY") != std::string::npos)
235 if (
annotation.find(
"STRCAT") != std::string::npos)
247 std::vector<std::pair<u32_t, u32_t>>
args =
267 std::vector<std::pair<u32_t, u32_t>>
args =
318 if (SVFUtil::isa<BaseObjVar>(
obj))
322 return as.getByteOffset(
gep);
324 else if (SVFUtil::isa<GepObjVar>(
obj))
332 assert(SVFUtil::isa<DummyObjVar>(
obj) &&
"Unknown object type");
356 if (SVFUtil::isa<BaseObjVar>(
obj))
374 else if (SVFUtil::isa<GepObjVar>(
obj))
396 "GEP RHS object has no offset from base");
438 const std::vector<std::string>
strcatGroup = {
"__strcat_chk",
"strcat",
"__wcscat_chk",
"wcscat"};
439 const std::vector<std::string>
strncatGroup = {
"__strncat_chk",
"strncat",
"__wcsncat_chk",
"wcsncat"};
461 assert(
false &&
"Unknown strcat function, please add it to strcatGroup or strncatGroup");
518 if (
offset.ub().getIntNumeral() >= size)
528 if (SVFUtil::isa<CallICFGNode>(node))
553 else if (
const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(
stmt))
571 std::string funcName =
callNode->getCalledFunction()->getName();
572 if (funcName ==
"UNSAFE_LOAD")
586 <<
" — " <<
callNode->toString() <<
"\n";
592 <<
" — Position: " <<
callNode->getSourceLoc() <<
"\n";
596 else if (funcName ==
"SAFE_LOAD")
600 if (
callNode->arg_size() < 1)
return;
608 <<
" — " <<
callNode->toString() <<
"\n";
614 <<
" — Position: " <<
callNode->getSourceLoc() <<
"\n";
628 if (
annotation.find(
"MEMCPY") != std::string::npos)
645 else if (
annotation.find(
"MEMSET") != std::string::npos)
650 else if (
annotation.find(
"STRCPY") != std::string::npos)
656 else if (
annotation.find(
"STRCAT") != std::string::npos)
686 if (!
AbsVal.isAddr())
return true;
696 else if (
as.isFreedMem(
addr))
Exception class for handling errors in Abstract Execution.
IntervalValue getStrlen(AbstractState &as, const SVF::SVFVar *strValue)
Calculates the length of a string.
ExtAPIType
Enumeration of external API types.
static AbstractInterpretation & getAEInstance()
AbstractState & getAbsStateFromTrace(const ICFGNode *node)
Retrieves the abstract state from the trace for a given ICFG node.
Set< const CallICFGNode * > checkpoints
static bool isNullMem(u32_t addr)
static bool isInvalidMem(u32_t addr)
const ICFGNode * getICFGNode() const
Get the ICFGNode related to the creation of this object.
bool isConstantByteSize() const
Check if byte size is a const value.
u32_t getByteSizeOfObj() const
Get the byte size of this object.
IntervalValue getAccessOffset(AbstractState &as, NodeID objId, const GepStmt *gep)
Retrieves the access offset for a given object and GEP statement.
void addToGepObjOffsetFromBase(const GepObjVar *obj, const IntervalValue &offset)
Adds an offset to a GEP object.
Map< std::string, std::vector< std::pair< u32_t, u32_t > > > extAPIBufOverflowCheckRules
Rules for checking buffer overflows in external APIs.
void detect(AbstractState &as, const ICFGNode *)
Detect buffer overflow issues within a node.
bool detectStrcpy(AbstractState &as, const CallICFGNode *call)
Detects buffer overflow in 'strcpy' function calls.
bool detectStrcat(AbstractState &as, const CallICFGNode *call)
Detects buffer overflow in 'strcat' function calls.
IntervalValue getGepObjOffsetFromBase(const GepObjVar *obj) const
Retrieves the offset of a GEP object from its base.
void handleStubFunctions(const CallICFGNode *)
Handles external API calls related to buffer overflow detection.
bool hasGepObjOffsetFromBase(const GepObjVar *obj) const
Checks if a GEP object has an associated offset.
bool canSafelyAccessMemory(AbstractState &as, const SVFVar *value, const IntervalValue &len)
Checks if memory can be safely accessed.
void initExtAPIBufOverflowCheckRules()
Initializes external API buffer overflow check rules.
void detectExtAPI(AbstractState &as, const CallICFGNode *call)
Handles external API calls related to buffer overflow detection.
void updateGepObjOffsetFromBase(AbstractState &as, AddressValue gepAddrs, AddressValue objAddrs, IntervalValue offset)
Updates the offset of a GEP object from its base.
void addBugToReporter(const AEException &e, const ICFGNode *node)
Adds a bug to the reporter based on an exception.
const std::string toString() const override
const ValVar * getArgument(u32_t ArgNo) const
Parameter operations.
const FunObjVar * getCalledFunction() const
static ExtAPI * getExtAPI()
const std::vector< std::string > & getExtFuncAnnotations(const FunObjVar *fun)
NodeType * getGNode(NodeID id) const
Get a node.
const SVFStmtList & getSVFStmts() const
static IntervalValue bottom()
Create the bottom IntervalValue [+inf, -inf].
static IntervalValue top()
Create the IntervalValue [-inf, +inf].
bool canSafelyDerefPtr(AbstractState &as, const SVFVar *ptr)
bool isUninit(AbstractValue v)
Checks if an Abstract Value is uninitialized.
void detect(AbstractState &as, const ICFGNode *node)
Detects nullptr dereferences issues within a node.
void addBugToReporter(const AEException &e, const ICFGNode *node)
Adds a bug to the reporter based on an exception.
void handleStubFunctions(const CallICFGNode *call)
Handles external API calls related to nullptr dereferences.
void detectExtAPI(AbstractState &as, const CallICFGNode *call)
Handle external API calls related to nullptr dereferences.
const BaseObjVar * getBaseObject(NodeID id) const
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
NodeID getId() const
Get ID.
virtual const std::string & getName() const
std::string sucMsg(const std::string &msg)
Returns successful message by converting a string into green string output.
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
std::ostream & errs()
Overwrite llvm::errs()
bool isExtCall(const FunObjVar *fun)
std::ostream & outs()
Overwrite llvm::outs()
llvm::IRBuilder IRBuilder