48 if (!SVFUtil::isa<CallICFGNode>(node))
61 ae.getStateMgr()->getGepByteOffset(
gep));
81 size =
ae.getStateMgr()->getAllocaInstByteSize(
addrStmt);
119 std::string funcName =
callNode->getCalledFunction()->getName();
121 if (funcName ==
"SAFE_BUFACCESS")
130 assert(
false &&
"SAFE_BUFACCESS size is bottom");
137 <<
" — " <<
callNode->toString() <<
"\n";
143 <<
" — Position: " <<
callNode->getSourceLoc() <<
"\n";
147 else if (funcName ==
"UNSAFE_BUFACCESS")
150 if (
callNode->arg_size() < 2)
return;
154 assert(
false &&
"UNSAFE_BUFACCESS size is bottom");
161 <<
" — " <<
callNode->toString() <<
"\n";
167 <<
" — Position: " <<
callNode->getSourceLoc() <<
"\n";
222 if (
annotation.find(
"MEMCPY") != std::string::npos)
224 if (
annotation.find(
"MEMSET") != std::string::npos)
226 if (
annotation.find(
"STRCPY") != std::string::npos)
228 if (
annotation.find(
"STRCAT") != std::string::npos)
240 std::vector<std::pair<u32_t, u32_t>>
args =
260 std::vector<std::pair<u32_t, u32_t>>
args =
311 if (SVFUtil::isa<BaseObjVar>(
obj))
313 return ae.getStateMgr()->getGepByteOffset(
gep);
315 else if (SVFUtil::isa<GepObjVar>(
obj))
321 assert(SVFUtil::isa<DummyObjVar>(
obj) &&
"Unknown object type");
347 if (SVFUtil::isa<BaseObjVar>(
obj))
365 else if (SVFUtil::isa<GepObjVar>(
obj))
387 "GEP RHS object has no offset from base");
421 const std::vector<std::string>
strcatGroup = {
"__strcat_chk",
"strcat",
"__wcscat_chk",
"wcscat"};
422 const std::vector<std::string>
strncatGroup = {
"__strncat_chk",
"strncat",
"__wcsncat_chk",
"wcsncat"};
444 assert(
false &&
"Unknown strcat function, please add it to strcatGroup or strncatGroup");
469 ae.updateAbsValue(value,
ptrVal, node);
488 size =
ae.getStateMgr()->getAllocaInstByteSize(
addrStmt);
506 if (
offset.ub().getIntNumeral() >= size)
516 if (SVFUtil::isa<CallICFGNode>(node))
541 else if (
const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(
stmt))
559 std::string funcName =
callNode->getCalledFunction()->getName();
561 if (funcName ==
"UNSAFE_LOAD")
574 <<
" — " <<
callNode->toString() <<
"\n";
580 <<
" — Position: " <<
callNode->getSourceLoc() <<
"\n";
584 else if (funcName ==
"SAFE_LOAD")
588 if (
callNode->arg_size() < 1)
return;
595 <<
" — " <<
callNode->toString() <<
"\n";
601 <<
" — Position: " <<
callNode->getSourceLoc() <<
"\n";
615 if (
annotation.find(
"MEMCPY") != std::string::npos)
632 else if (
annotation.find(
"MEMSET") != std::string::npos)
637 else if (
annotation.find(
"STRCPY") != std::string::npos)
643 else if (
annotation.find(
"STRCAT") != std::string::npos)
673 if (!
AbsVal.isAddr())
return true;
683 else if (
ae.getAbsState(node).isFreedMem(
addr))
Exception class for handling errors in Abstract Execution.
ExtAPIType
Enumeration of external API types.
static AbstractInterpretation & getAEInstance()
u32_t getIDFromAddr(u32_t addr) const
Return the internal index if addr is an address otherwise return the value of idx.
static bool isNullMem(u32_t addr)
static bool isBlackHoleObjAddr(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.
void addToGepObjOffsetFromBase(const GepObjVar *obj, const IntervalValue &offset)
Adds an offset to a GEP object.
void detect(const ICFGNode *) override
Detect buffer overflow issues within a node.
Map< std::string, std::vector< std::pair< u32_t, u32_t > > > extAPIBufOverflowCheckRules
Rules for checking buffer overflows in external APIs.
IntervalValue getAccessOffset(NodeID objId, const GepStmt *gep)
Retrieves the access offset for a given object and GEP statement.
void updateGepObjOffsetFromBase(const ICFGNode *node, AddressValue gepAddrs, AddressValue objAddrs, IntervalValue offset)
Updates the offset of a GEP object from its base.
void detectExtAPI(const CallICFGNode *call)
Handles external API calls related to buffer overflow detection.
bool canSafelyAccessMemory(const ValVar *value, const IntervalValue &len, const ICFGNode *node)
Checks if memory can be safely accessed.
IntervalValue getGepObjOffsetFromBase(const GepObjVar *obj) const
Retrieves the offset of a GEP object from its base.
bool detectStrcpy(const CallICFGNode *call)
Detects buffer overflow in 'strcpy' function calls.
void handleStubFunctions(const CallICFGNode *) override
Handles external API calls related to buffer overflow detection.
bool hasGepObjOffsetFromBase(const GepObjVar *obj) const
Checks if a GEP object has an associated offset.
void initExtAPIBufOverflowCheckRules()
Initializes external API buffer overflow check rules.
bool detectStrcat(const CallICFGNode *call)
Detects buffer overflow in 'strcat' function calls.
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)
const SVFStmtList & getSVFStmts() const
static IntervalValue top()
Create the IntervalValue [-inf, +inf].
bool canSafelyDerefPtr(const ValVar *ptr, const ICFGNode *node)
bool isUninit(AbstractValue v)
Checks if an Abstract Value is uninitialized.
void handleStubFunctions(const CallICFGNode *call) override
Handles external API calls related to nullptr dereferences.
void detect(const ICFGNode *node) override
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 detectExtAPI(const CallICFGNode *call)
Handle external API calls related to nullptr dereferences.
const BaseObjVar * getBaseObject(NodeID id) const
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
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