Question: #include Assignment - 4 . h #include #include #include #include using namespace SVF; using namespace llvm; using namespace std; / / Local set to

#include "Assignment-4.h"
#include
#include
#include
#include
using namespace SVF;
using namespace llvm;
using namespace std;
// Local set to store paths for testing verification
std::set collectedPaths;
// Get sources function names read from checker_source_api collected from a text file
std::set &TaintGraphTraversal::identifySources()
{
static std::set sources;
for (const CallICFGNode *cs : pag->getCallSiteSet())
{
const SVFFunction *fun = SVFUtil::getCallee(cs->getCallSite());
if (checker_source_api.find(fun->getName())!= checker_source_api.end())
{
sources.insert(cs);
}
}
return sources;
}
// Get sinks function names read from checker_sink_api collected from a text file
std::set &TaintGraphTraversal::identifySinks()
{
static std::set sinks;
for (const CallICFGNode *cs : pag->getCallSiteSet())
{
const SVFFunction *fun = SVFUtil::getCallee(cs->getCallSite());
if (checker_sink_api.find(fun->getName())!= checker_sink_api.end())
{
sinks.insert(cs);
}
}
return sinks;
}
// Start taint checking
void TaintGraphTraversal::taintChecking()
{
// Configure sources and sinks for taint analysis
readSrcSnkFromFile("./Assignment-4/SrcSnk.txt");
ander = new AndersenPTA(pag);
ander->analyze();
for (const CallICFGNode *src : identifySources())
{
for (const CallICFGNode *snk : identifySinks())
{
if (aliasCheck(src, snk))
reachability(src, snk);
}
}
// Output collected paths for testing verification
cout << "Collected paths:" << endl;
for (const auto &path : collectedPaths)
{
cout << path << endl;
}
}
// Collect and format ICFG path details
void TaintGraphTraversal::collectICFGPath(std::vector &path)
{
std::stringstream pathStr;
pathStr << "START";
for (size_t i =0; i < path.size(); ++i)
{
pathStr <<"->"<< path[i];
}
pathStr <<"->END";
// Store the formatted path in the local collectedPaths set
collectedPaths.insert(pathStr.str());
// Debug print to check path being added
cout << "Adding path: "<< pathStr.str()<< endl;
}
// Parse the `SrcSnk.txt` file for sources and sinks
void TaintGraphTraversal::readSrcSnkFromFile(const string &filename)
{
std::ifstream file(filename);
if (!file.is_open())
{
return;
}
std::string line;
// Read sources
if (getline(file, line))
{
std::istringstream ss(line.substr(1, line.size()-2)); // Remove {}
std::string api;
while (ss >> api)
{
checker_source_api.insert(api);
}
}
// Read sinks
if (getline(file, line))
{
std::istringstream ss(line.substr(1, line.size()-2)); // Remove {}
std::string api;
while (ss >> api)
{
checker_sink_api.insert(api);
}
}
file.close();
}
// Perform alias checking with dyn_cast for safety
bool TaintGraphTraversal::aliasCheck(const CallICFGNode *src, const CallICFGNode *snk)
{
const RetICFGNode *retNode = SVFUtil::dyn_cast(src);
const CallICFGNode *callNode = SVFUtil::dyn_cast(snk);
if (!retNode ||!callNode)
{
// Return false if casting fails
return false;
}
const SVFVar *srcRet = retNode->getActualRet();
const auto &snkParams = callNode->getActualParms();
for (const auto *param : snkParams)
{
if (ander->alias(srcRet->getId(), param->getId()))
{
return true;
}
}
return false;
}
Why does it not work and pass my test files:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!