Static Value-Flow Analysis
Public Member Functions | Static Public Member Functions | List of all members
SVF::DoubleFreeBug Class Reference

#include <SVFBugReport.h>

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

Public Member Functions

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

Static Public Member Functions

static bool classof (const GenericBug *bug)
 ClassOf. More...
 

Additional Inherited Members

- Public Types inherited from SVF::GenericBug
enum  BugType {
  FULLBUFOVERFLOW , PARTIALBUFOVERFLOW , NEVERFREE , PARTIALLEAK ,
  DOUBLEFREE , FILENEVERCLOSE , FILEPARTIALCLOSE , FULLNULLPTRDEREFERENCE ,
  PARTIALNULLPTRDEREFERENCE
}
 
typedef std::vector< SVFBugEventEventStack
 
- Static Public Attributes inherited from SVF::GenericBug
static const std::map< GenericBug::BugType, std::stringBugType2Str
 
- Protected Attributes inherited from SVF::GenericBug
BugType bugType
 
const EventStack bugEventStack
 

Detailed Description

Definition at line 208 of file SVFBugReport.h.

Constructor & Destructor Documentation

◆ DoubleFreeBug()

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

Definition at line 211 of file SVFBugReport.h.

211  :
GenericBug(BugType bugType, const EventStack &bugEventStack)
note: should be initialized with a bugEventStack
Definition: SVFBugReport.h:95
const EventStack bugEventStack
Definition: SVFBugReport.h:91

Member Function Documentation

◆ classof()

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

ClassOf.

Definition at line 218 of file SVFBugReport.h.

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

◆ getBugDescription()

cJSON * DoubleFreeBug::getBugDescription ( ) const
virtual

Implements SVF::GenericBug.

Definition at line 166 of file SVFBugReport.cpp.

167 {
168  cJSON *bugDescription = cJSON_CreateObject();
169 
170  cJSON *pathInfo = cJSON_CreateArray();
171  auto lastBranchEventIt = bugEventStack.end() - 1;
172  for(auto eventIt = bugEventStack.begin(); eventIt != lastBranchEventIt; eventIt++)
173  {
174  cJSON *newBranch = cJSON_CreateObject();
175  cJSON *branchLoc = cJSON_Parse((*eventIt).getEventLoc().c_str());
176  if(branchLoc == nullptr) branchLoc = cJSON_CreateObject();
177  cJSON *branchCondition = cJSON_CreateString((*eventIt).getEventDescription().c_str());
178 
179  cJSON_AddItemToObject(newBranch, "BranchLoc", branchLoc);
180  cJSON_AddItemToObject(newBranch, "BranchCond", branchCondition);
181 
182  cJSON_AddItemToArray(pathInfo, newBranch);
183  }
184  cJSON_AddItemToObject(bugDescription, "DoubleFreePath", pathInfo);
185 
186  return bugDescription;
187 }
Definition: cJSON.h:104

◆ printBugToTerminal()

void DoubleFreeBug::printBugToTerminal ( ) const
virtual

Implements SVF::GenericBug.

Definition at line 189 of file SVFBugReport.cpp.

190 {
191  SVFUtil::errs() << SVFUtil::bugMsg2("\t Double Free :") << " memory allocation at : ("
192  << GenericBug::getLoc() << ")\n";
193 
194  SVFUtil::errs() << "\t\t double free path: \n";
195  auto lastBranchEventIt = bugEventStack.end() - 1;
196  for(auto eventIt = bugEventStack.begin(); eventIt != lastBranchEventIt; eventIt++)
197  {
198  SVFUtil::errs() << "\t\t --> (" << (*eventIt).getEventLoc() << "|" << (*eventIt).getEventDescription() << ") \n";
199  }
200  SVFUtil::errs() << "\n";
201 }
const std::string getLoc() const
returns bug location as json format string
std::ostream & errs()
Overwrite llvm::errs()
Definition: SVFUtil.h:56
std::string bugMsg2(const std::string &msg)
Definition: SVFUtil.cpp:86

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