Static Value-Flow Analysis
Public Types | Public Member Functions | Protected Attributes | List of all members
SVF::SVFBugReport Class Reference

#include <SVFBugReport.h>

Public Types

typedef SVF::Set< const GenericBug * > BugSet
 

Public Member Functions

 SVFBugReport ()=default
 
 ~SVFBugReport ()
 
void setStat (double time, std::string mem, double coverage)
 
void addSaberBug (GenericBug::BugType bugType, const GenericBug::EventStack &eventStack)
 
void addAbsExecBug (GenericBug::BugType bugType, const GenericBug::EventStack &eventStack, s64_t allocLowerBound, s64_t allocUpperBound, s64_t accessLowerBound, s64_t accessUpperBound)
 
void dumpToJsonFile (const std::string &filePath) const
 
const BugSetgetBugSet () const
 

Protected Attributes

BugSet bugSet
 
double time
 
std::string mem
 
double coverage
 

Detailed Description

Definition at line 288 of file SVFBugReport.h.

Member Typedef Documentation

◆ BugSet

Definition at line 293 of file SVFBugReport.h.

Constructor & Destructor Documentation

◆ SVFBugReport()

SVF::SVFBugReport::SVFBugReport ( )
default

◆ ~SVFBugReport()

SVFBugReport::~SVFBugReport ( )

Definition at line 331 of file SVFBugReport.cpp.

332 {
333  for(auto bugIt: bugSet)
334  {
335  delete bugIt;
336  }
337 }

Member Function Documentation

◆ addAbsExecBug()

void SVF::SVFBugReport::addAbsExecBug ( GenericBug::BugType  bugType,
const GenericBug::EventStack eventStack,
s64_t  allocLowerBound,
s64_t  allocUpperBound,
s64_t  accessLowerBound,
s64_t  accessUpperBound 
)
inline

add bugs

Definition at line 367 of file SVFBugReport.h.

369  {
371  GenericBug *newBug = nullptr;
372  switch(bugType)
373  {
375  {
376  newBug = new FullBufferOverflowBug(eventStack, allocLowerBound, allocUpperBound, accessLowerBound, accessUpperBound);
377  bugSet.insert(newBug);
378  break;
379  }
381  {
382  newBug = new PartialBufferOverflowBug(eventStack, allocLowerBound, allocUpperBound, accessLowerBound, accessUpperBound);
383  bugSet.insert(newBug);
384  break;
385  }
387  {
388  newBug = new FullNullPtrDereferenceBug(eventStack);
389  bugSet.insert(newBug);
390  break;
391  }
393  {
394  newBug = new PartialNullPtrDereferenceBug(eventStack);
395  bugSet.insert(newBug);
396  break;
397  }
398  default:
399  {
400  assert(false && "Abstract Execution does NOT have this bug type!");
401  break;
402  }
403  }
404 
405  // when add a bug, also print it to terminal
406  //newBug->printBugToTerminal();
407  }

◆ addSaberBug()

void SVF::SVFBugReport::addSaberBug ( GenericBug::BugType  bugType,
const GenericBug::EventStack eventStack 
)
inline

create and add the bug

Definition at line 315 of file SVFBugReport.h.

316  {
318  GenericBug *newBug = nullptr;
319  switch(bugType)
320  {
322  {
323  newBug = new NeverFreeBug(eventStack);
324  bugSet.insert(newBug);
325  break;
326  }
328  {
329  newBug = new PartialLeakBug(eventStack);
330  bugSet.insert(newBug);
331  break;
332  }
334  {
335  newBug = new DoubleFreeBug(eventStack);
336  bugSet.insert(newBug);
337  break;
338  }
340  {
341  newBug = new FileNeverCloseBug(eventStack);
342  bugSet.insert(newBug);
343  break;
344  }
346  {
347  newBug = new FilePartialCloseBug(eventStack);
348  bugSet.insert(newBug);
349  break;
350  }
351  default:
352  {
353  assert(false && "saber does NOT have this bug type!");
354  break;
355  }
356  }
357 
358  // when add a bug, also print it to terminal
359  newBug->printBugToTerminal();
360  }

◆ dumpToJsonFile()

void SVFBugReport::dumpToJsonFile ( const std::string filePath) const

Add defects

Add bug information to JSON

Add event information to JSON

Dump single bug to JSON string and write to file

Destroy the cJSON object

Add program information

Definition at line 339 of file SVFBugReport.cpp.

340 {
341  std::map<u32_t, std::string> eventType2Str =
342  {
343  {SVFBugEvent::CallSite, "call site"},
344  {SVFBugEvent::Caller, "caller"},
345  {SVFBugEvent::Loop, "loop"},
346  {SVFBugEvent::Branch, "branch"}
347  };
348 
349  ofstream jsonFile(filePath, ios::out);
350 
351  jsonFile << "{\n";
352 
354  jsonFile << "\"Defects\": [\n";
355  size_t commaCounter = bugSet.size() - 1;
356  for (auto bugPtr : bugSet)
357  {
358  cJSON *singleDefect = cJSON_CreateObject();
359 
361  cJSON *bugType = cJSON_CreateString(
362  GenericBug::BugType2Str.at(bugPtr->getBugType()).c_str());
363  cJSON_AddItemToObject(singleDefect, "DefectType", bugType);
364 
365  cJSON *bugLoc = cJSON_Parse(bugPtr->getLoc().c_str());
366  if (bugLoc == nullptr)
367  {
368  bugLoc = cJSON_CreateObject();
369  }
370  cJSON_AddItemToObject(singleDefect, "Location", bugLoc);
371 
372  cJSON *bugFunction = cJSON_CreateString(
373  bugPtr->getFuncName().c_str());
374  cJSON_AddItemToObject(singleDefect, "Function", bugFunction);
375 
376  cJSON_AddItemToObject(singleDefect, "Description",
377  bugPtr->getBugDescription());
378 
380  cJSON *eventList = cJSON_CreateArray();
381  const GenericBug::EventStack &bugEventStack = bugPtr->getEventStack();
382  if (BufferOverflowBug::classof(bugPtr))
383  {
384  // Add only when bug is context sensitive
385  for (const SVFBugEvent &event : bugEventStack)
386  {
387  if (event.getEventType() == SVFBugEvent::SourceInst)
388  {
389  continue;
390  }
391 
392  cJSON *singleEvent = cJSON_CreateObject();
393  // Event type
394  cJSON *eventType = cJSON_CreateString(
395  eventType2Str[event.getEventType()].c_str());
396  cJSON_AddItemToObject(singleEvent, "EventType", eventType);
397  // Function name
398  cJSON *eventFunc = cJSON_CreateString(
399  event.getFuncName().c_str());
400  cJSON_AddItemToObject(singleEvent, "Function", eventFunc);
401  // Event loc
402  cJSON *eventLoc = cJSON_Parse(event.getEventLoc().c_str());
403  if (eventLoc == nullptr)
404  {
405  eventLoc = cJSON_CreateObject();
406  }
407  cJSON_AddItemToObject(singleEvent, "Location", eventLoc);
408  // Event description
409  cJSON *eventDescription = cJSON_CreateString(
410  event.getEventDescription().c_str());
411  cJSON_AddItemToObject(singleEvent, "Description", eventDescription);
412 
413  cJSON_AddItemToArray(eventList, singleEvent);
414  }
415  }
416  cJSON_AddItemToObject(singleDefect, "Events", eventList);
417 
419  char *singleDefectStr = cJSON_Print(singleDefect);
420  jsonFile << singleDefectStr;
421  if (commaCounter != 0)
422  {
423  jsonFile << ",\n";
424  }
425  commaCounter--;
426 
428  cJSON_Delete(singleDefect);
429  }
430  jsonFile << "\n],\n";
431 
433  jsonFile << "\"Time\": " << time << ",\n";
434  jsonFile << "\"Memory\": \"" << mem << "\",\n";
435  jsonFile << "\"Coverage\": " << coverage << "\n";
436 
437  jsonFile << "}";
438  jsonFile.close();
439 }
cJSON_Delete(null)
static bool classof(const GenericBug *bug)
ClassOf.
Definition: SVFBugReport.h:138
static const std::map< GenericBug::BugType, std::string > BugType2Str
Definition: SVFBugReport.h:87
std::vector< SVFBugEvent > EventStack
Definition: SVFBugReport.h:83
std::string mem
Definition: SVFBugReport.h:298
Definition: cJSON.h:104

◆ getBugSet()

const BugSet& SVF::SVFBugReport::getBugSet ( ) const
inline

Definition at line 419 of file SVFBugReport.h.

420  {
421  return bugSet;
422  }

◆ setStat()

void SVF::SVFBugReport::setStat ( double  time,
std::string  mem,
double  coverage 
)
inline

Definition at line 303 of file SVFBugReport.h.

304  {
305  this->time = time;
306  this->mem = mem;
307  this->coverage = coverage;
308  }

Member Data Documentation

◆ bugSet

BugSet SVF::SVFBugReport::bugSet
protected

Definition at line 296 of file SVFBugReport.h.

◆ coverage

double SVF::SVFBugReport::coverage
protected

Definition at line 299 of file SVFBugReport.h.

◆ mem

std::string SVF::SVFBugReport::mem
protected

Definition at line 298 of file SVFBugReport.h.

◆ time

double SVF::SVFBugReport::time
protected

Definition at line 297 of file SVFBugReport.h.


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