44#define SSE_FUNC_PROCESS(LLVM_NAME ,FUNC_NAME) \
45 auto sse_##FUNC_NAME = [this](const CallICFGNode *callNode) { \
47 const SVFVar* argVar = callNode->getArgument(0); \
48 const AbstractValue& argVal = mgr->getAbstractValue(argVar, callNode); \
49 if (!argVal.isInterval() && !argVal.isAddr()) return; \
50 u32_t rhs = argVal.getInterval().lb().getIntNumeral(); \
51 s32_t res = FUNC_NAME(rhs); \
52 const SVFVar* retVar = callNode->getRetICFGNode()->getActualRet(); \
53 mgr->updateAbstractValue(retVar, IntervalValue(res), callNode); \
56 func_map[#FUNC_NAME] = sse_##FUNC_NAME;
113 if (
callNode->arg_size() < 2)
return;
117 <<
", PrintVal: " <<
itv.toString() <<
", Loc:" <<
callNode->getSourceLoc() << std::endl;
124 if (
callNode->arg_size() < 2)
return;
128 assert(
lbVal.getInterval().is_numeral() &&
ubVal.getInterval().is_numeral());
133 const ICFGNode* node = SVFUtil::cast<ValVar>(
callNode->getArgument(0))->getICFGNode();
136 if (SVFUtil::isa<LoadStmt>(
stmt))
151 if (
callNode->arg_size() < 2)
return;
154 if (!
dstVal.isAddr())
return;
165 if (
callNode->arg_size() < 3)
return;
168 if (!
dstVal.isAddr())
return;
188 if (
callNode->arg_size() < 3)
return;
203 if (
callNode->arg_size() < 2)
return;
206 if (
callNode->getArgument(2)->getType()->isArrayTy())
208 elemSize = SVFUtil::dyn_cast<SVFArrayType>(
209 callNode->getArgument(2)->getType())->getTypeOfElement()->getByteSize();
211 else if (
callNode->getArgument(2)->getType()->isPointerTy())
237 if (
callNode->arg_size() < 3)
return;
239 std::string
snum = std::to_string(
num);
247 if (
callNode->arg_size() < 1)
return;
261 if (
callNode->arg_size() < 4)
return;
271 if (
callNode->arg_size() < 1)
return;
288 "VOS_MemFree",
"cfree",
"free",
"free_all_mem",
"freeaddrinfo",
289 "gcry_mpi_release",
"gcry_sexp_release",
"globfree",
"nhfree",
290 "obstack_free",
"safe_cfree",
"safe_free",
"safefree",
"safexfree",
291 "sm_free",
"vim_free",
"xfree",
"SSL_CTX_free",
"SSL_free",
"XFree"
315 if (
const CallICFGNode *call = SVFUtil::dyn_cast<CallICFGNode>(node))
317 if (
const FunObjVar *fun = call->getCalledFunction())
376 if (!
val.getInterval().is_numeral())
380 if ((
char)
val.getInterval().getIntNumeral() ==
'\0')
384 str0.push_back((
char)
val.getInterval().getIntNumeral());
392 assert(fun &&
"FunObjVar* is nullptr");
397 if (
annotation.find(
"MEMCPY") != std::string::npos)
399 if (
annotation.find(
"MEMSET") != std::string::npos)
401 if (
annotation.find(
"STRCPY") != std::string::npos)
403 if (
annotation.find(
"STRCAT") != std::string::npos)
446 if (
name.find(
"ncat") != std::string::npos)
466 if (
var->getType()->isArrayTy())
468 return SVFUtil::dyn_cast<SVFArrayType>(
var->getType())
469 ->getTypeOfElement()->getByteSize();
471 if (
var->getType()->isPointerTy())
473 assert(
false &&
"unsupported type for element size");
482 return !
len.isBottom() && !
len.lb().is_minus_infinity();
527 if (
val.getInterval().is_numeral() &&
528 (
char)
val.getInterval().getIntNumeral() ==
'\0')
633 ->getTypeOfElement()->getByteSize();
641 assert(
false &&
"unsupported type for element size");
655 if (
as.inAddrToValTable(
objId))
691 ub =
static_cast<s64_t>(std::numeric_limits<s32_t>::max());
692 lb =
static_cast<s64_t>(std::numeric_limits<s32_t>::min());
696 ub =
static_cast<s64_t>(std::numeric_limits<u32_t>::max());
697 lb =
static_cast<s64_t>(std::numeric_limits<u32_t>::min());
704 ub =
static_cast<s64_t>(std::numeric_limits<s16_t>::max());
705 lb =
static_cast<s64_t>(std::numeric_limits<s16_t>::min());
709 ub =
static_cast<s64_t>(std::numeric_limits<u16_t>::max());
710 lb =
static_cast<s64_t>(std::numeric_limits<u16_t>::min());
717 ub =
static_cast<s64_t>(std::numeric_limits<int8_t>::max());
718 lb =
static_cast<s64_t>(std::numeric_limits<int8_t>::min());
722 ub =
static_cast<s64_t>(std::numeric_limits<uint8_t>::max());
723 lb =
static_cast<s64_t>(std::numeric_limits<uint8_t>::min());
728 else if (SVFUtil::isa<SVFOtherType>(
type))
731 s64_t ub =
static_cast<s64_t>(std::numeric_limits<s32_t>::max());
732 s64_t lb =
static_cast<s64_t>(std::numeric_limits<s32_t>::min());
#define SSE_FUNC_PROCESS(LLVM_NAME,FUNC_NAME)
AbstractStateManager * mgr
Pointer to the state manager.
void initExtFunMap()
Initializes the external function map.
AbsExtAPI(AbstractStateManager *mgr)
Constructor for AbsExtAPI.
IntervalValue getStrlen(const ValVar *strValue, const ICFGNode *node)
Calculate the length of a null-terminated string in abstract state.
void handleMemcpy(const ValVar *dst, const ValVar *src, const IntervalValue &len, u32_t start_idx, const ICFGNode *node)
Core memcpy: copy len bytes from src to dst starting at dst[start_idx].
void handleExtAPI(const CallICFGNode *call)
Handles an external API call.
void handleStrncat(const CallICFGNode *call)
static bool isValidLength(const IntervalValue &len)
Check if an interval length is usable (not bottom, not unbounded).
Set< const CallICFGNode * > checkpoints
std::string strRead(const ValVar *rhs, const ICFGNode *node)
Reads a string from the abstract state.
u32_t getElementSize(const ValVar *var)
Get the byte size of each element for a pointer/array variable.
void handleMemset(const ValVar *dst, const IntervalValue &elem, const IntervalValue &len, const ICFGNode *node)
SVFIR * svfir
Pointer to the SVF intermediate representation.
ExtAPIType
Enumeration of external API types.
AbstractState & getAbstractState(const ICFGNode *node)
Retrieves the abstract state from the trace for a given ICFG node.
IntervalValue getRangeLimitFromType(const SVFType *type)
Gets the range limit from a type.
ICFG * icfg
Pointer to the interprocedural control flow graph.
void handleStrcat(const CallICFGNode *call)
void handleStrcpy(const CallICFGNode *call)
Map< std::string, std::function< void(const CallICFGNode *)> > func_map
Map of function names to handlers.
void updateAbstractValue(const ValVar *var, const AbstractValue &val, const ICFGNode *node)
Write a top-level variable's abstract value into abstractTrace[node].
AbstractState & getAbstractState(const ICFGNode *node)
Retrieve the abstract state for a given ICFG node. Asserts if absent.
u32_t getAllocaInstByteSize(const AddrStmt *addr)
Get the byte size of a stack allocation.
const AbstractValue & getAbstractValue(const ValVar *var, const ICFGNode *node)
AddressValue getGepObjAddrs(const ValVar *pointer, IntervalValue offset)
Compute GEP object addresses for a pointer at a given element offset.
static bool isBlackHoleObjAddr(u32_t addr)
void join_with(const AbstractValue &other)
IntervalValue & getInterval()
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.
const ValVar * getArgument(u32_t ArgNo) const
Parameter operations.
const FunObjVar * getCalledFunction() const
const RetICFGNode * getRetICFGNode() const
Return callsite.
static ExtAPI * getExtAPI()
const std::vector< std::string > & getExtFuncAnnotations(const FunObjVar *fun)
iterator begin()
Iterators.
virtual const std::string toString() const
const SVFStmtList & getSVFStmts() const
const std::string toString() const
void set_to_top()
Set current IntervalValue as top.
static IntervalValue top()
Create the IntervalValue [-inf, +inf].
const ValVar * getRHSVar() const
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
static const Option< bool > NullDerefCheck
nullptr dereference checker, Default: false
static const Option< bool > BufferOverflowCheck
buffer overflow checker, Default: false
const SVFVar * getActualRet() const
Return actual return parameter.
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.
virtual const SVFType * getType() const
virtual const std::string & getName() const
int ispunct(int argument)
int isblank(int character)
int isalnum(int character)
int isalpha(int character)
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()
llvm::IRBuilder IRBuilder