44#define SSE_FUNC_PROCESS(LLVM_NAME ,FUNC_NAME) \
45 auto sse_##FUNC_NAME = [this](const CallICFGNode *callNode) { \
47 AbstractState& as = getAbsStateFromTrace(callNode); \
48 u32_t rhs_id = callNode->getArgument(0)->getId(); \
49 if (!as.inVarToValTable(rhs_id)) return; \
50 u32_t rhs = as[rhs_id].getInterval().lb().getIntNumeral(); \
51 s32_t res = FUNC_NAME(rhs); \
52 u32_t lhsId = callNode->getRetICFGNode()->getActualRet()->getId(); \
53 as[lhsId] = IntervalValue(res); \
56 func_map[#FUNC_NAME] = sse_##FUNC_NAME;
100 if (
as[
arg0].getInterval().equals(
as[
arg1].getInterval()))
115 if (
callNode->arg_size() < 2)
return;
119 assert(
as.inVarToValTable(
num_id) &&
"print() should pass integer");
122 <<
", PrintVal: " <<
itv.toString() <<
", Loc:" <<
callNode->getSourceLoc() << std::endl;
129 if (
callNode->arg_size() < 2)
return;
135 num.getInterval().set_to_top();
137 const ICFGNode* node = SVFUtil::cast<ValVar>(
callNode->getArgument(0))->getICFGNode();
140 if (SVFUtil::isa<LoadStmt>(
stmt))
155 if (
callNode->arg_size() < 2)
return;
176 if (
callNode->arg_size() < 3)
return;
205 if (
callNode->arg_size() < 3)
return;
222 if (
callNode->arg_size() < 2)
return;
228 if (
callNode->getArgument(2)->getType()->isArrayTy())
230 elemSize = SVFUtil::dyn_cast<SVFArrayType>(
231 callNode->getArgument(2)->getType())->getTypeOfElement()->getByteSize();
233 else if (
callNode->getArgument(2)->getType()->isPointerTy())
263 if (
callNode->arg_size() < 3)
return;
268 std::string
snum = std::to_string(
num);
275 if (
callNode->arg_size() < 1)
return;
295 if (
callNode->arg_size() < 4)
return;
307 if (
callNode->arg_size() < 1)
return;
326 "VOS_MemFree",
"cfree",
"free",
"free_all_mem",
"freeaddrinfo",
327 "gcry_mpi_release",
"gcry_sexp_release",
"globfree",
"nhfree",
328 "obstack_free",
"safe_cfree",
"safe_free",
"safefree",
"safexfree",
329 "sm_free",
"vim_free",
"xfree",
"SSL_CTX_free",
"SSL_free",
"XFree"
342 assert(0 &&
"No preAbsTrace for this node");
359 if (!
as.inVarToAddrsTable(
rhs->getId()))
continue;
368 if (!
val.getInterval().is_numeral())
372 if ((
char)
val.getInterval().getIntNumeral() ==
'\0')
376 str0.push_back((
char)
val.getInterval().getIntNumeral());
385 assert(fun &&
"FunObjVar* is nullptr");
390 if (
annotation.find(
"MEMCPY") != std::string::npos)
392 if (
annotation.find(
"MEMSET") != std::string::npos)
394 if (
annotation.find(
"STRCPY") != std::string::npos)
396 if (
annotation.find(
"STRCAT") != std::string::npos)
410 if (
as.inVarToAddrsTable(
lhsId))
445 if (
name.find(
"ncat") != std::string::npos)
465 if (
var->getType()->isArrayTy())
467 return SVFUtil::dyn_cast<SVFArrayType>(
var->getType())
468 ->getTypeOfElement()->getByteSize();
470 if (
var->getType()->isPointerTy())
475 return SVFUtil::dyn_cast<SVFArrayType>(
elemType)
476 ->getTypeOfElement()->getByteSize();
481 assert(
false &&
"unsupported type for element size");
490 return !
len.isBottom() && !
len.lb().is_minus_infinity();
535 if (
val.getInterval().is_numeral() &&
536 (
char)
val.getInterval().getIntNumeral() ==
'\0')
646 ->getTypeOfElement()->getByteSize();
657 assert(
false &&
"unsupported type for element size");
665 if (!
as.inVarToAddrsTable(
dstId))
671 if (
as.inAddrToValTable(
objId))
707 ub =
static_cast<s64_t>(std::numeric_limits<s32_t>::max());
708 lb =
static_cast<s64_t>(std::numeric_limits<s32_t>::min());
712 ub =
static_cast<s64_t>(std::numeric_limits<u32_t>::max());
713 lb =
static_cast<s64_t>(std::numeric_limits<u32_t>::min());
720 ub =
static_cast<s64_t>(std::numeric_limits<s16_t>::max());
721 lb =
static_cast<s64_t>(std::numeric_limits<s16_t>::min());
725 ub =
static_cast<s64_t>(std::numeric_limits<u16_t>::max());
726 lb =
static_cast<s64_t>(std::numeric_limits<u16_t>::min());
733 ub =
static_cast<s64_t>(std::numeric_limits<int8_t>::max());
734 lb =
static_cast<s64_t>(std::numeric_limits<int8_t>::min());
738 ub =
static_cast<s64_t>(std::numeric_limits<uint8_t>::max());
739 lb =
static_cast<s64_t>(std::numeric_limits<uint8_t>::min());
744 else if (SVFUtil::isa<SVFOtherType>(
type))
747 s64_t ub =
static_cast<s64_t>(std::numeric_limits<s32_t>::max());
748 s64_t lb =
static_cast<s64_t>(std::numeric_limits<s32_t>::min());
#define SSE_FUNC_PROCESS(LLVM_NAME,FUNC_NAME)
std::string strRead(AbstractState &as, const SVFVar *rhs)
Reads a string from the abstract state.
void handleMemset(AbstractState &as, const SVFVar *dst, IntervalValue elem, IntervalValue len)
void initExtFunMap()
Initializes the external function map.
IntervalValue getStrlen(AbstractState &as, const SVF::SVFVar *strValue)
Calculate the length of a null-terminated string in abstract state.
Map< const ICFGNode *, AbstractState > & abstractTrace
Map of ICFG nodes to abstract states.
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).
AbsExtAPI(Map< const ICFGNode *, AbstractState > &traces)
Constructor for AbsExtAPI.
AbstractState & getAbsStateFromTrace(const ICFGNode *node)
Retrieves the abstract state from the trace for a given ICFG node.
void handleMemcpy(AbstractState &as, const SVF::SVFVar *dst, const SVF::SVFVar *src, IntervalValue len, u32_t start_idx)
Core memcpy: copy len bytes from src to dst starting at dst[start_idx].
SVFIR * svfir
Pointer to the SVF intermediate representation.
ExtAPIType
Enumeration of external API types.
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)
u32_t getElementSize(AbstractState &as, const SVFVar *var)
Get the byte size of each element for a pointer/array variable.
Map< std::string, std::function< void(const CallICFGNode *)> > func_map
Map of function names to handlers.
static AbstractInterpretation & getAEInstance()
Set< const CallICFGNode * > checkpoints
static bool isBlackHoleObjAddr(u32_t addr)
void join_with(const AbstractValue &other)
IntervalValue & getInterval()
NodeID getRHSVarID() const
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)
const SVFStmtList & getSVFStmts() const
const BoundedInt & ub() const
Return the upper bound.
bool is_numeral() const
Return true if the IntervalValue is a number [num, num].
const std::string toString() const
static IntervalValue top()
Create the IntervalValue [-inf, +inf].
const BoundedInt & lb() const
Return the lower bound.
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
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.
NodeID getId() const
Get ID.
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