40#define SSE_FUNC_PROCESS(LLVM_NAME ,FUNC_NAME) \
41 auto sse_##FUNC_NAME = [this](const CallICFGNode *callNode) { \
43 AbstractState& as = getAbsStateFromTrace(callNode); \
44 u32_t rhs_id = callNode->getArgument(0)->getId(); \
45 if (!as.inVarToValTable(rhs_id)) return; \
46 u32_t rhs = as[rhs_id].getInterval().lb().getIntNumeral(); \
47 s32_t res = FUNC_NAME(rhs); \
48 u32_t lhsId = callNode->getRetICFGNode()->getActualRet()->getId(); \
49 as[lhsId] = IntervalValue(res); \
52 func_map[#FUNC_NAME] = sse_##FUNC_NAME;
96 if (
as[
arg0].getInterval().equals(
as[
arg1].getInterval()))
111 if (
callNode->arg_size() < 2)
return;
115 assert(
as.inVarToValTable(
num_id) &&
"print() should pass integer");
118 <<
", PrintVal: " <<
itv.toString() <<
", Loc:" <<
callNode->getSourceLoc() << std::endl;
125 if (
callNode->arg_size() < 2)
return;
131 num.getInterval().set_to_top();
133 const ICFGNode* node = SVFUtil::cast<ValVar>(
callNode->getArgument(0))->getICFGNode();
136 if (SVFUtil::isa<LoadStmt>(
stmt))
151 if (
callNode->arg_size() < 2)
return;
172 if (
callNode->arg_size() < 3)
return;
201 if (
callNode->arg_size() < 3)
return;
218 if (
callNode->arg_size() < 2)
return;
224 if (
callNode->getArgument(2)->getType()->isArrayTy())
226 elemSize = SVFUtil::dyn_cast<SVFArrayType>(
227 callNode->getArgument(2)->getType())->getTypeOfElement()->getByteSize();
229 else if (
callNode->getArgument(2)->getType()->isPointerTy())
259 if (
callNode->arg_size() < 3)
return;
264 std::string
snum = std::to_string(
num);
272 if (
callNode->arg_size() < 1)
return;
299 if (
as.inVarToAddrsTable(
dstid))
310 if (
val.getInterval().is_numeral() && (
char)
val.getInterval().getIntNumeral() ==
'\0')
332 if (
callNode->arg_size() < 4)
return;
348 assert(0 &&
"No preAbsTrace for this node");
364 if (!
as.inVarToAddrsTable(
rhs->getId()))
continue;
373 if (!
val.getInterval().is_numeral())
377 if ((
char)
val.getInterval().getIntNumeral() ==
'\0')
381 str0.push_back((
char)
val.getInterval().getIntNumeral());
390 assert(fun &&
"SVFFunction* is nullptr");
395 if (
annotation.find(
"MEMCPY") != std::string::npos)
397 if (
annotation.find(
"MEMSET") != std::string::npos)
399 if (
annotation.find(
"STRCPY") != std::string::npos)
401 if (
annotation.find(
"STRCAT") != std::string::npos)
415 if (
as.inVarToAddrsTable(
lhsId))
504 if (
val.getInterval().is_numeral() && (
char)
val.getInterval().getIntNumeral() ==
'\0')
510 if (
strValue->getType()->isArrayTy())
512 elemSize = SVFUtil::dyn_cast<SVFArrayType>(
strValue->getType())->getTypeOfElement()->getByteSize();
514 else if (
strValue->getType()->isPointerTy())
519 elemSize = SVFUtil::dyn_cast<SVFArrayType>(
elemType)->getTypeOfElement()->getByteSize();
530 assert(
false &&
"we cannot support this type");
550 const std::vector<std::string>
strcatGroup = {
"__strcat_chk",
"strcat",
"__wcscat_chk",
"wcscat"};
551 const std::vector<std::string>
strncatGroup = {
"__strncat_chk",
"strncat",
"__wcsncat_chk",
"wcsncat"};
575 assert(
false &&
"unknown strcat function, please add it to strcatGroup or strncatGroup");
586 elemSize = SVFUtil::dyn_cast<SVFArrayType>(dst->
getType())->getTypeOfElement()->getByteSize();
594 elemSize = SVFUtil::dyn_cast<SVFArrayType>(
elemType)->getTypeOfElement()->getByteSize();
605 assert(
false &&
"we cannot support this type");
618 for (
const auto &dst:
expr_dst.getAddrs())
620 for (
const auto &src:
expr_src.getAddrs())
623 if (
as.inAddrToValTable(
objId))
625 as.store(dst,
as.load(src));
627 else if (
as.inAddrToAddrsTable(
objId))
629 as.store(dst,
as.load(src));
644 elemSize = SVFUtil::dyn_cast<SVFArrayType>(dst->
getType())->getTypeOfElement()->getByteSize();
659 assert(
false &&
"we cannot support this type");
666 if (
as.inVarToAddrsTable(
dstId))
672 if (
as.inAddrToValTable(
objId))
711 ub =
static_cast<s64_t>(std::numeric_limits<s32_t>::max());
712 lb =
static_cast<s64_t>(std::numeric_limits<s32_t>::min());
716 ub =
static_cast<s64_t>(std::numeric_limits<u32_t>::max());
717 lb =
static_cast<s64_t>(std::numeric_limits<u32_t>::min());
724 ub =
static_cast<s64_t>(std::numeric_limits<s16_t>::max());
725 lb =
static_cast<s64_t>(std::numeric_limits<s16_t>::min());
729 ub =
static_cast<s64_t>(std::numeric_limits<u16_t>::max());
730 lb =
static_cast<s64_t>(std::numeric_limits<u16_t>::min());
737 ub =
static_cast<s64_t>(std::numeric_limits<int8_t>::max());
738 lb =
static_cast<s64_t>(std::numeric_limits<int8_t>::min());
742 ub =
static_cast<s64_t>(std::numeric_limits<u_int8_t>::max());
743 lb =
static_cast<s64_t>(std::numeric_limits<u_int8_t>::min());
748 else if (SVFUtil::isa<SVFOtherType>(
type))
751 s64_t ub =
static_cast<s64_t>(std::numeric_limits<s32_t>::max());
752 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)
Handles the memset API call.
void initExtFunMap()
Initializes the external function map.
IntervalValue getStrlen(AbstractState &as, const SVF::SVFVar *strValue)
Calculates the length of a string.
Map< const ICFGNode *, AbstractState > & abstractTrace
Map of ICFG nodes to abstract states.
void handleExtAPI(const CallICFGNode *call)
Handles an external API call.
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.
const SVFVar * getSVFVar(const SVFValue *val)
Retrieves the SVF variable from a given SVF value.
void handleMemcpy(AbstractState &as, const SVF::SVFVar *dst, const SVF::SVFVar *src, IntervalValue len, u32_t start_idx)
Handles the memcpy API call.
SVFIR * svfir
Pointer to the SVF intermediate representation.
void handleStrcat(const SVF::CallICFGNode *call)
Handles the strcat API call.
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 handleStrcpy(const CallICFGNode *call)
Handles the strcpy API call.
Map< std::string, std::function< void(const CallICFGNode *)> > func_map
Map of function names to handlers.
static AbstractInterpretation & getAEInstance()
Set< const CallICFGNode * > checkpoints
static u32_t getInternalID(u32_t idx)
Return the internal index if idx is an address otherwise return the value of idx.
void join_with(const AbstractValue &other)
IntervalValue & getInterval()
NodeID getRHSVarID() const
const ValVar * getArgument(u32_t ArgNo) const
Parameter operations.
const RetICFGNode * getRetICFGNode() const
Return callsite.
const SVFFunction * getCalledFunction() const
const std::vector< std::string > & getExtFuncAnnotations(const SVFFunction *fun)
static ExtAPI * getExtAPI()
bool hasGNode(NodeID id) const
Has a node.
NodeType * getGNode(NodeID id) const
Get a node.
const SVFStmtList & getSVFStmts() const
const ICFGNode * getRepNode(const ICFGNode *node) const
NodeID getValueNode(const SVFValue *V)
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.
const SVFBaseNode * getGNode() const
Get the reference value to this object.
u32_t getByteSizeOfObj() const
Get the byte size of this object.
bool isConstantByteSize() const
Check if byte size is a const value.
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
const SVFVar * getActualRet() const
Return actual return parameter.
NodeID getId() const
Get ID.
const MemObj * getBaseObj(NodeID id) const
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
const std::string & getName() const
virtual const SVFType * getType() const
Return type of the value.
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::ostream & errs()
Overwrite llvm::errs()
llvm::IRBuilder IRBuilder