Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cdg null deref #1551

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions svf/include/Graphs/CDG.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef GenericEdge<CDGNode> GenericCDGEdgeTy;
class CDGEdge : public GenericCDGEdgeTy
{
public:
typedef std::pair<const SVFValue *, s32_t> BranchCondition;
typedef std::pair<const SVFVar *, s32_t> BranchCondition;

/// Constructor
CDGEdge(CDGNode *s, CDGNode *d) : GenericCDGEdgeTy(s, d, 0)
Expand Down Expand Up @@ -73,7 +73,7 @@ class CDGEdge : public GenericCDGEdgeTy
return brConditions;
}

void insertBranchCondition(const SVFValue *pNode, s32_t branchID)
void insertBranchCondition(const SVFVar *pNode, s32_t branchID)
{
brConditions.insert(std::make_pair(pNode, branchID));
}
Expand Down Expand Up @@ -288,7 +288,7 @@ class CDG : public GenericCDGTy
}

/// Add CDG edges from nodeid pair
void addCDGEdgeFromSrcDst(const ICFGNode *src, const ICFGNode *dst, const SVFValue *pNode, s32_t branchID);
void addCDGEdgeFromSrcDst(const ICFGNode *src, const ICFGNode *dst, const SVFVar *pNode, s32_t branchID);

};
} // end namespace SVF
Expand Down
2 changes: 1 addition & 1 deletion svf/lib/Graphs/CDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

CDG *CDG::controlDg = nullptr;

void CDG::addCDGEdgeFromSrcDst(const ICFGNode *src, const ICFGNode *dst, const SVFValue *pNode, s32_t branchID)
void CDG::addCDGEdgeFromSrcDst(const ICFGNode *src, const ICFGNode *dst, const SVFVar *pNode, s32_t branchID)

Check warning on line 35 in svf/lib/Graphs/CDG.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/Graphs/CDG.cpp#L35

Added line #L35 was not covered by tests
{
if (!hasCDGNode(src->getId()))
{
Expand Down
48 changes: 36 additions & 12 deletions svf/lib/Util/CDGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,14 @@
ICFG *icfg = PAG::getPAG()->getICFG();
assert(!BB->getICFGNodeList().empty() && "empty bb?");
const ICFGNode *pred = BB->back();
const ICFGEdge *edge = nullptr;
for (const auto &node: Succ->getICFGNodeList())
if (const CallICFGNode* callNode = dyn_cast<CallICFGNode>(pred))
{
if (const ICFGEdge *e = icfg->getICFGEdge(pred, node, ICFGEdge::ICFGEdgeK::IntraCF))
{
edge = e;
break;
}
// not a branch statement:
// invoke void %3(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2)
// to label %invoke.cont1 unwind label %lpad
pred = callNode->getRetICFGNode();
}
const ICFGEdge *edge = icfg->getICFGEdge(pred, Succ->front(), ICFGEdge::ICFGEdgeK::IntraCF);

Check warning on line 98 in svf/lib/Util/CDGBuilder.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/Util/CDGBuilder.cpp#L98

Added line #L98 was not covered by tests
if (const IntraCFGEdge *intraEdge = SVFUtil::dyn_cast<IntraCFGEdge>(edge))
{
if(intraEdge->getCondition())
Expand Down Expand Up @@ -190,9 +189,15 @@
for (const auto &it2: it.second)
{
const SVFBasicBlock *controllingBB = it2.first;
// const ICFGNode *controlNode = _bbToNode[it.first].first;
// if(!controlNode) continue;
const ICFGNode *controlNode = it.first->getICFGNodeList().back();
if (const CallICFGNode* callNode =
SVFUtil::dyn_cast<CallICFGNode>(controlNode))

Check warning on line 194 in svf/lib/Util/CDGBuilder.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/Util/CDGBuilder.cpp#L194

Added line #L194 was not covered by tests
{
// not a branch statement:
// invoke void %3(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2)
// to label %invoke.cont1 unwind label %lpad
controlNode = callNode->getRetICFGNode();

Check warning on line 199 in svf/lib/Util/CDGBuilder.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/Util/CDGBuilder.cpp#L199

Added line #L199 was not covered by tests
}
if (!controlNode) continue;
// controlNode control at pos
for (const auto &controllee: controllingBB->getICFGNodeList())
Expand All @@ -201,9 +206,28 @@
_nodeDependentOnMap[controllee][controlNode].insert(it2.second.begin(), it2.second.end());
for (s32_t pos: it2.second)
{
_controlDG->addCDGEdgeFromSrcDst(controlNode, controllee,
SVFUtil::dyn_cast<IntraICFGNode>(controlNode)->getInst(),
pos);
if (const IntraICFGNode* intraNode =
dyn_cast<IntraICFGNode>(controlNode))

Check warning on line 210 in svf/lib/Util/CDGBuilder.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/Util/CDGBuilder.cpp#L210

Added line #L210 was not covered by tests
{
assert(intraNode->getSVFStmts().size() == 1 &&

Check warning on line 212 in svf/lib/Util/CDGBuilder.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/Util/CDGBuilder.cpp#L212

Added line #L212 was not covered by tests
"not a branch stmt?");
const SVFVar* condition =
SVFUtil::cast<BranchStmt>(
intraNode->getSVFStmts().front())
->getCondition();
_controlDG->addCDGEdgeFromSrcDst(controlNode, controllee,

Check warning on line 218 in svf/lib/Util/CDGBuilder.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/Util/CDGBuilder.cpp#L217-L218

Added lines #L217 - L218 were not covered by tests
condition,
pos);
} else {
// not a branch statement:
// invoke void %3(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2)
// to label %invoke.cont1 unwind label %lpad
SVFIR* pag = PAG::getPAG();
_controlDG->addCDGEdgeFromSrcDst(

Check warning on line 226 in svf/lib/Util/CDGBuilder.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/Util/CDGBuilder.cpp#L225-L226

Added lines #L225 - L226 were not covered by tests
controlNode, controllee,
pag->getGNode(pag->getNullPtr()), pos);

Check warning on line 228 in svf/lib/Util/CDGBuilder.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/Util/CDGBuilder.cpp#L228

Added line #L228 was not covered by tests
}

}
}
}
Expand Down
Loading