Static Value-Flow Analysis
Loading...
Searching...
No Matches
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, BoundedInt allocLowerBound, BoundedInt allocUpperBound, BoundedInt accessLowerBound, BoundedInt accessUpperBound)
void dumpToJsonFile (const std::string &filePath) const
const BugSet & getBugSet () const

Protected Attributes

BugSet bugSet
double time
std::string mem
double coverage

Detailed Description

Definition at line 287 of file SVFBugReport.h.

Member Typedef Documentation

◆ BugSet

Definition at line 292 of file SVFBugReport.h.

Constructor & Destructor Documentation

◆ SVFBugReport()

SVF::SVFBugReport::SVFBugReport ( )
default

◆ ~SVFBugReport()

SVFBugReport::~SVFBugReport ( )

Definition at line 346 of file SVFBugReport.cpp.

347{
348 for(auto bugIt: bugSet)
349 {
350 delete bugIt;
351 }
352}

Member Function Documentation

◆ addAbsExecBug()

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

add bugs

Definition at line 366 of file SVFBugReport.h.

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

◆ addSaberBug()

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

create and add the bug

Definition at line 314 of file SVFBugReport.h.

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

◆ 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 354 of file SVFBugReport.cpp.

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

◆ getBugSet()

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

Definition at line 418 of file SVFBugReport.h.

419 {
420 return bugSet;
421 }

◆ setStat()

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

Definition at line 302 of file SVFBugReport.h.

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

Member Data Documentation

◆ bugSet

BugSet SVF::SVFBugReport::bugSet
protected

Definition at line 295 of file SVFBugReport.h.

◆ coverage

double SVF::SVFBugReport::coverage
protected

Definition at line 298 of file SVFBugReport.h.

◆ mem

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

Definition at line 297 of file SVFBugReport.h.

◆ time

double SVF::SVFBugReport::time
protected

Definition at line 296 of file SVFBugReport.h.


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