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

Add SVFBugRecoder and modify source loc format #1067

Merged
merged 13 commits into from
Apr 26, 2023

Conversation

JoelYYoung
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Apr 24, 2023

Codecov Report

Merging #1067 (21e8041) into master (53983e0) will decrease coverage by 0.33%.
The diff coverage is 36.00%.

❗ Current head 21e8041 differs from pull request most recent head 5eb7db8. Consider uploading reports for the commit 5eb7db8 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1067      +/-   ##
==========================================
- Coverage   62.72%   62.39%   -0.33%     
==========================================
  Files         218      220       +2     
  Lines       21620    21863     +243     
==========================================
+ Hits        13561    13642      +81     
- Misses       8059     8221     +162     
Impacted Files Coverage Δ
svf/include/SABER/FileChecker.h 0.00% <ø> (ø)
svf/include/SABER/LeakChecker.h 100.00% <ø> (ø)
svf/include/SABER/ProgSlice.h 100.00% <ø> (ø)
svf/include/SABER/SrcSnkDDA.h 91.66% <ø> (ø)
svf/lib/SABER/FileChecker.cpp 0.00% <0.00%> (ø)
svf/lib/SABER/SrcSnkDDA.cpp 82.47% <ø> (ø)
svf/lib/Util/SVFBugReport.cpp 20.83% <20.83%> (ø)
svf/include/Util/SVFBugReport.h 66.00% <66.00%> (ø)
svf-llvm/lib/LLVMUtil.cpp 68.68% <100.00%> (+0.07%) ⬆️
svf/lib/SABER/DoubleFreeChecker.cpp 68.85% <100.00%> (-0.51%) ⬇️
... and 2 more

... and 2 files with indirect coverage changes

typedef std::vector<GenericEvent *> EventStack;

public:
enum BugType{BOA, NEVERFREE, PARTIALLEAK, DOUBLEFREE, FILENEVERCLOSE, FILEPARTIALCLOSE};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BOA=>BuffOverflow

protected:
BugType bugType;
const SVFInstruction * bugInst;
EventStack *bugEventStack = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not assign nullptr in the constructor?

inline BugType getBugType(){ return bugType; }
std::string getLoc();
std::string getFuncName();
inline void setEventStack(EventStack *eventStack) { bugEventStack = eventStack; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need setEventStack ? why not set this in the constructor?

typedef std::vector<GenericEvent *> EventStack;
typedef std::vector<GenericEvent *> EventSet;
typedef std::vector<GenericBug *> BugVector;
typedef std::vector<EventStack *> EventStackVector;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have a set and a vector?

Comment on lines 253 to 257
auto bugIt = bugVector.begin();
for(;bugIt != bugVector.end(); bugIt ++){
delete (*bugIt);
}
auto eventStackIt = eventStackVector.begin();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For(auto event : eventSet)
delete event

enum BugType{BOA, NEVERFREE, PARTIALLEAK, DOUBLEFREE, FILENEVERCLOSE, FILEPARTIALCLOSE};

protected:
BugType bugType;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classof method for each subclass.

virtual ~GenericBug() = default;

inline BugType getBugType(){ return bugType; }
std::string getLoc();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string

EventStack *bugEventStack = nullptr;

public:
inline GenericBug(BugType bugType, const SVFInstruction * bugInst): bugType(bugType), bugInst(bugInst){ };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GenericBug(BugType bugType, eventstack)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove const SVFInstruction * bugInst,

typedef std::vector<EventStack *> EventStackVector;

protected:
EventStack eventStack; // maintain current execution events
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BugVector bugVector; and move eventStack to each Bug class


class GenericEvent{
public:
enum EventType{Branch, Caller, CallSite, Loop};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "SourceInst'' event

/// branch statement and branch condition true or false
protected:
const BranchStmt *branchStmt;
std::string description;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove description and make it retrievable in getEventDescription

public:
SVFBugReport() = default;
~SVFBugReport();
typedef std::vector<GenericBug *> BugVector;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it a set.

SVFUtil::errs() << "\n";
}

const std::string CallSiteEvent::getFuncName() const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be unfeasible because getName() returns const std::string but not const std::string&.

return description;
}

const std::string BranchEvent::getFuncName() const
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&


const std::string BranchEvent::getFuncName() const
{
return branchStmt->getInst()->getFunction()->getName();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be unfeasible because getName() returns const std::string but not const std::string&.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, pls use const std::string


SVFBugReport::~SVFBugReport()
{
auto bugIt = bugVector.begin();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for( bug : bugSet)
delete bug;

}
}

std::string SVFBugReport::toString()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better change the method to "void SVFBugReport::toJson()". Never return large string!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chang to void dumpToFile(const std::string filePath).

/// branch statement and branch condition true or false
protected:
const BranchStmt *branchStmt;
bool branchCondition;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this book field or it can be obtained via BranchStmt?

const CallICFGNode *callSite;

public:
inline CallSiteEvent(const CallICFGNode *callSite): GenericEvent(GenericEvent::CallSite), callSite(callSite){ }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove inline for constructor

const SVFInstruction *sourceSVFInst;

public:
inline SourceInstructionEvent(const SVFInstruction *sourceSVFInst):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above and following constructors


class BufferOverflowBug: public GenericBug{
protected:
long long allocLowerBound, allocUpperBound, accessLowerBound, accessUpperBound;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use SVF’s type and DON’T use std long long


public:
inline BufferOverflowBug(GenericBug::BugType bugType, EventStack eventStack,
long long allocLowerBound, long long allocUpperBound,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above and followings

protected:
Set<std::string> conditionalFreePath;
public:
PartialLeakBug(EventStack bugEventStack, Set<std::string> conditionalFreePath):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have an event stack, do we need a set of condfree paths? Can we put these into the event stack?


class NeverFreeBug : public GenericBug{
public:
NeverFreeBug(EventStack bugEventStack):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use “const EventStack& “ to avoid copy construction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that copy construction is necessary here because the EventStack created by detector is a function local variable, so it had better to be copied and saved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can use new to dynamically create EventStack in saber's reportBug function and destroy it in the destructor of GenericBug. I am not sure if its better.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that copy construction is necessary here because the EventStack created by detector is a function local variable, so it had better to be copied and saved.

It should be const reference because it will do the copy in GeneralBug’s constructor.

protected:
Set<std::string> conditionalFreePath;
public:
PartialLeakBug(EventStack bugEventStack, Set<std::string> conditionalFreePath):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use const EventStack&

same for the following constructors


class DoubleFreeBug : public GenericBug{
protected:
Set<std::string> doubleFreePath;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this or put into the event stack?

Copy link
Contributor Author

@JoelYYoung JoelYYoung Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you refer to doing so for DoubleFreeBug only, I think it's feasible, but may loss consistency with other bug classes like FilePartialCloseBug, ParitalLeakBug, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the strings in this vector? Can we get or extract the from the event stack?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the reason for not doing so for other bug classes is that eventStack should be used to store events happening on the execution path from entry to the bug site, but not side effects like partial free paths and partial close paths.

SVFUtil::errs() << "\t\t Events : \n";

auto eventIt = bugEventStack.begin();
for(; eventIt != bugEventStack.end(); eventIt ++){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (event : bugEventStack)
….


const std::string GenericBug::getLoc() const
{
return bugEventStack.at(bugEventStack.size() -1)->getEventLoc();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an assertion, otherwise how can you sure the size-1 is the element you want?

/// note: should be initialized with a bugEventStack
inline GenericBug(BugType bugType, EventStack bugEventStack): bugType(bugType), bugEventStack(bugEventStack){ };

virtual ~GenericBug() = default;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the destructor? How did you release the memory of the events in EventStack?


public:
/// note: should be initialized with a bugEventStack
inline GenericBug(BugType bugType, EventStack bugEventStack): bugType(bugType), bugEventStack(bugEventStack){ };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const EventStack&

}
}

void SVFBugReport::dumpToFile(const std::string& filePath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dumpToFile => dumpToJsonFile


public:
/// note: should be initialized with a bugEventStack
GenericBug(BugType bugType, EventStack bugEventStack):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const EventStack& bugEventStack


class GenericBug{
public:
typedef std::vector<GenericEvent *> EventStack;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const GenericEvent*

public:
SVFBugReport() = default;
~SVFBugReport();
typedef SVF::Set<GenericBug *> BugSet;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const GenericBug*

* usage: addBug<GenericBug::BOA>(BufferOverflowBug(bugInst, 0, 10, 1, 11))
*/
template <typename T>
void addBug(T bug)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void addBug(eventstack, flag){

switch (xx)
case1:
xxxx

default:
assert(false && "no such kind of bug");

}

{
T *newBug = new T(bug);
bugSet.insert(newBug);
GenericBug *newBug;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GenericBug *newBug = nullptr;

switch(bugType){
case GenericBug::NEVERFREE:{
newBug = new NeverFreeBug(eventStack);
bugSet.insert(newBug);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        bugSet.insert(new NeverFreeBug(eventStack));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newBug is use at line 333 newBug->printBugToTerminal()


void addAbsExecBug(GenericBug::BugType bugType, const GenericBug::EventStack &eventStack,
s64_t allocLowerBound, s64_t allocUpperBound, s64_t accessLowerBound, s64_t accessUpperBound){
GenericBug *newBug;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GenericBug *newBug = nullptr;

}
};

class SourceInstructionEvent: public GenericEvent{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SourceInstructionEvent => SourceInstEvent

auto stmt = PAG::getPAG()->getValueEdges(tinst);
assert(stmt.size() == 1 && "returned SVFStmtSet should be of size 1!");
if(pathAllocator->isNegCond(*it))
eventStack.push_back(new BranchEvent(*(stmt.begin()), false));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new BranchEvent(tinst, false)

@yuleisui yuleisui merged commit 5c98c07 into SVF-tools:master Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants