Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::DoubleFreeBug Class Reference

#include <SVFBugReport.h>

Inheritance diagram for SVF::DoubleFreeBug:
SVF::GenericBug

Public Member Functions

 DoubleFreeBug (const EventStack &bugEventStack)
cJSON * getBugDescription () const
void printBugToTerminal () const
Public Member Functions inherited from SVF::GenericBug
 GenericBug (BugType bugType, const EventStack &bugEventStack)
 note: should be initialized with a bugEventStack
virtual ~GenericBug ()=default
BugType getBugType () const
 returns bug type
const std::string getLoc () const
 returns bug location as json format string
const std::string getFuncName () const
 return bug source function name
const EventStack & getEventStack () const

Static Public Member Functions

static bool classof (const GenericBug *bug)
 ClassOf.

Additional Inherited Members

Public Types inherited from SVF::GenericBug
enum  BugType {
  FULLBUFOVERFLOW , PARTIALBUFOVERFLOW , NEVERFREE , PARTIALLEAK ,
  DOUBLEFREE , FILENEVERCLOSE , FILEPARTIALCLOSE , FULLNULLPTRDEREFERENCE ,
  PARTIALNULLPTRDEREFERENCE
}
typedef std::vector< SVFBugEvent > EventStack
Static Public Attributes inherited from SVF::GenericBug
static const OrderedMap< GenericBug::BugType, std::string > BugType2Str
Protected Attributes inherited from SVF::GenericBug
BugType bugType
const EventStack bugEventStack

Detailed Description

Definition at line 207 of file SVFBugReport.h.

Constructor & Destructor Documentation

◆ DoubleFreeBug()

SVF::DoubleFreeBug::DoubleFreeBug ( const EventStack & bugEventStack)
inline

Definition at line 210 of file SVFBugReport.h.

210 :
GenericBug(BugType bugType, const EventStack &bugEventStack)
note: should be initialized with a bugEventStack
const EventStack bugEventStack

Member Function Documentation

◆ classof()

bool SVF::DoubleFreeBug::classof ( const GenericBug * bug)
inlinestatic

ClassOf.

Definition at line 217 of file SVFBugReport.h.

218 {
219 return bug->getBugType() == GenericBug::DOUBLEFREE;
220 }

◆ getBugDescription()

cJSON * DoubleFreeBug::getBugDescription ( ) const
virtual

Implements SVF::GenericBug.

Definition at line 181 of file SVFBugReport.cpp.

182{
183 cJSON *bugDescription = cJSON_CreateObject();
184
185 cJSON *pathInfo = cJSON_CreateArray();
186 auto lastBranchEventIt = bugEventStack.end() - 1;
187 for(auto eventIt = bugEventStack.begin(); eventIt != lastBranchEventIt; eventIt++)
188 {
189 cJSON *newBranch = cJSON_CreateObject();
190 cJSON *branchLoc = cJSON_Parse((*eventIt).getEventLoc().c_str());
191 if(branchLoc == nullptr) branchLoc = cJSON_CreateObject();
192 cJSON *branchCondition = cJSON_CreateString((*eventIt).getEventDescription().c_str());
193
194 cJSON_AddItemToObject(newBranch, "BranchLoc", branchLoc);
195 cJSON_AddItemToObject(newBranch, "BranchCond", branchCondition);
196
197 cJSON_AddItemToArray(pathInfo, newBranch);
198 }
199 cJSON_AddItemToObject(bugDescription, "DoubleFreePath", pathInfo);
200
201 return bugDescription;
202}
struct cJSON cJSON

◆ printBugToTerminal()

void DoubleFreeBug::printBugToTerminal ( ) const
virtual

Implements SVF::GenericBug.

Definition at line 204 of file SVFBugReport.cpp.

205{
206 SVFUtil::errs() << SVFUtil::bugMsg2("\t Double Free :") << " memory allocation at : ("
207 << GenericBug::getLoc() << ")\n";
208
209 SVFUtil::errs() << "\t\t double free path: \n";
210 auto lastBranchEventIt = bugEventStack.end() - 1;
211 for(auto eventIt = bugEventStack.begin(); eventIt != lastBranchEventIt; eventIt++)
212 {
213 SVFUtil::errs() << "\t\t --> (" << (*eventIt).getEventLoc() << "|" << (*eventIt).getEventDescription() << ") \n";
214 }
215 SVFUtil::errs() << "\n";
216}
const std::string getLoc() const
returns bug location as json format string
std::ostream & errs()
Overwrite llvm::errs().
Definition SVFUtil.h:64
std::string bugMsg2(const std::string &msg)
Definition SVFUtil.cpp:108

The documentation for this class was generated from the following files: