Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFBugReport.h
Go to the documentation of this file.
1//===- SVFBugReport.h -- Base class for statistics---------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23//
24// Created by JoelYang on 2023/4/19.
25//
26
27#ifndef SVF_BUGRECODER_H
28#define SVF_BUGRECODER_H
29
30#include <string>
31#include <vector>
32
33#include "Util/cJSON.h"
34#include "Util/GeneralType.h"
35
36#define BRANCHFLAGMASK 0x00000010
37#define EVENTTYPEMASK 0x0000000f
38
39namespace SVF
40{
41
42class ICFGNode;
43
50{
51public:
53 {
54 Branch = 0x1,
55 Caller = 0x2,
56 CallSite = 0x3,
57 Loop = 0x4,
58 SourceInst = 0x5
59 };
60
61protected:
64
65public:
67 virtual ~SVFBugEvent() = default;
68
69 inline u32_t getEventType() const
70 {
72 }
73 virtual const std::string getEventDescription() const;
74 virtual const std::string getFuncName() const;
75 virtual const std::string getEventLoc() const;
76};
77
79{
80public:
81 typedef std::vector<SVFBugEvent> EventStack;
82
83public:
86
87protected:
90
91public:
95 {
96 assert(bugEventStack.size() != 0 && "bugEventStack should NOT be empty!");
97 }
98 virtual ~GenericBug() = default;
99 //GenericBug(const GenericBug &) = delete;
101 inline BugType getBugType() const
102 {
103 return bugType;
104 }
106 const std::string getLoc() const;
108 const std::string getFuncName() const;
109
110 inline const EventStack& getEventStack() const
111 {
112 return bugEventStack;
113 }
114
115 virtual cJSON *getBugDescription() const = 0;
116 virtual void printBugToTerminal() const = 0;
117};
118
141
157
173
175{
176public:
179
180 cJSON *getBugDescription() const;
181 void printBugToTerminal() const;
182
184 static inline bool classof(const GenericBug *bug)
185 {
186 return bug->getBugType() == GenericBug::NEVERFREE;
187 }
188};
189
191{
192public:
195
196 cJSON *getBugDescription() const;
197 void printBugToTerminal() const;
198
200 static inline bool classof(const GenericBug *bug)
201 {
202 return bug->getBugType() == GenericBug::PARTIALLEAK;
203 }
204};
205
207{
208public:
211
212 cJSON *getBugDescription() const;
213 void printBugToTerminal() const;
214
216 static inline bool classof(const GenericBug *bug)
217 {
218 return bug->getBugType() == GenericBug::DOUBLEFREE;
219 }
220};
221
223{
224public:
227
228 cJSON *getBugDescription() const;
229 void printBugToTerminal() const;
230
232 static inline bool classof(const GenericBug *bug)
233 {
234 return bug->getBugType() == GenericBug::FILENEVERCLOSE;
235 }
236};
237
239{
240public:
243
244 cJSON *getBugDescription() const;
245 void printBugToTerminal() const;
246
248 static inline bool classof(const GenericBug *bug)
249 {
250 return bug->getBugType() == GenericBug::FILEPARTIALCLOSE;
251 }
252};
253
255{
256public:
259
260 cJSON *getBugDescription() const;
261 void printBugToTerminal() const;
262
264 static inline bool classof(const GenericBug *bug)
265 {
266 return bug->getBugType() == GenericBug::FULLNULLPTRDEREFERENCE;
267 }
268};
269
271{
272public:
275
276 cJSON *getBugDescription() const;
277 void printBugToTerminal() const;
278
280 static inline bool classof(const GenericBug *bug)
281 {
282 return bug->getBugType() == GenericBug::PARTIALNULLPTRDEREFERENCE;
283 }
284};
285
287{
288public:
289 SVFBugReport() = default;
292
293protected:
294 BugSet bugSet; // maintain bugs
295 double time; // time (sec)
296 std::string mem; // string memory (KB)
297 double coverage; // coverage (%)
298
299public:
300 // set time, mem and coverage
301 void setStat(double time, std::string mem, double coverage)
302 {
303 this->time = time;
304 this->mem = mem;
305 this->coverage = coverage;
306 }
307
308 /*
309 * function: pass bug type (i.e., GenericBug::NEVERFREE) and eventStack as parameter,
310 * it will add the bug into bugQueue.
311 * usage: addSaberBug(GenericBug::NEVERFREE, eventStack)
312 */
314 {
316 GenericBug *newBug = nullptr;
317 switch(bugType)
318 {
320 {
322 bugSet.insert(newBug);
323 break;
324 }
326 {
328 bugSet.insert(newBug);
329 break;
330 }
332 {
334 bugSet.insert(newBug);
335 break;
336 }
338 {
340 bugSet.insert(newBug);
341 break;
342 }
344 {
346 bugSet.insert(newBug);
347 break;
348 }
349 default:
350 {
351 assert(false && "saber does NOT have this bug type!");
352 break;
353 }
354 }
355
356 // when add a bug, also print it to terminal
357 newBug->printBugToTerminal();
358 }
359
360 /*
361 * function: pass bug type (i.e., GenericBug::FULLBUFOVERFLOW) and eventStack as parameter,
362 * it will add the bug into bugQueue.
363 * usage: addAbsExecBug(GenericBug::FULLBUFOVERFLOW, eventStack, 0, 10, 11, 11)
364 */
366 s64_t allocLowerBound, s64_t allocUpperBound, s64_t accessLowerBound, s64_t accessUpperBound)
367 {
369 GenericBug *newBug = nullptr;
370 switch(bugType)
371 {
373 {
374 newBug = new FullBufferOverflowBug(eventStack, allocLowerBound, allocUpperBound, accessLowerBound, accessUpperBound);
375 bugSet.insert(newBug);
376 break;
377 }
379 {
380 newBug = new PartialBufferOverflowBug(eventStack, allocLowerBound, allocUpperBound, accessLowerBound, accessUpperBound);
381 bugSet.insert(newBug);
382 break;
383 }
385 {
387 bugSet.insert(newBug);
388 break;
389 }
391 {
393 bugSet.insert(newBug);
394 break;
395 }
396 default:
397 {
398 assert(false && "Abstract Execution does NOT have this bug type!");
399 break;
400 }
401 }
402
403 // when add a bug, also print it to terminal
404 //newBug->printBugToTerminal();
405 }
406
407 /*
408 * function: pass file path, open the file and dump bug report as JSON format
409 * usage: dumpToFile("/path/to/file")
410 */
411 void dumpToJsonFile(const std::string& filePath) const;
412
413 /*
414 * function: get underlying bugset
415 * usage: getBugSet()
416 */
417 const BugSet &getBugSet() const
418 {
419 return bugSet;
420 }
421
422};
423}
424
425#endif
#define EVENTTYPEMASK
cJSON * getBugDescription() const
static bool classof(const GenericBug *bug)
ClassOf.
BufferOverflowBug(GenericBug::BugType bugType, const EventStack &eventStack, s64_t allocLowerBound, s64_t allocUpperBound, s64_t accessLowerBound, s64_t accessUpperBound)
void printBugToTerminal() const
static bool classof(const GenericBug *bug)
ClassOf.
cJSON * getBugDescription() const
DoubleFreeBug(const EventStack &bugEventStack)
void printBugToTerminal() const
cJSON * getBugDescription() const
static bool classof(const GenericBug *bug)
ClassOf.
FileNeverCloseBug(const EventStack &bugEventStack)
void printBugToTerminal() const
cJSON * getBugDescription() const
FilePartialCloseBug(const EventStack &bugEventStack)
static bool classof(const GenericBug *bug)
ClassOf.
static bool classof(const GenericBug *bug)
ClassOf.
FullBufferOverflowBug(const EventStack &eventStack, s64_t allocLowerBound, s64_t allocUpperBound, s64_t accessLowerBound, s64_t accessUpperBound)
static bool classof(const GenericBug *bug)
ClassOf.
FullNullPtrDereferenceBug(const EventStack &bugEventStack)
GenericBug(BugType bugType, const EventStack &bugEventStack)
note: should be initialized with a bugEventStack
static const OrderedMap< GenericBug::BugType, std::string > BugType2Str
const EventStack & getEventStack() const
BugType getBugType() const
returns bug type
virtual ~GenericBug()=default
virtual void printBugToTerminal() const =0
const std::string getLoc() const
returns bug location as json format string
const EventStack bugEventStack
std::vector< SVFBugEvent > EventStack
virtual cJSON * getBugDescription() const =0
const std::string getFuncName() const
return bug source function name
cJSON * getBugDescription() const
NeverFreeBug(const EventStack &bugEventStack)
static bool classof(const GenericBug *bug)
ClassOf.
void printBugToTerminal() const
PartialBufferOverflowBug(const EventStack &eventStack, s64_t allocLowerBound, s64_t allocUpperBound, s64_t accessLowerBound, s64_t accessUpperBound)
static bool classof(const GenericBug *bug)
ClassOf.
void printBugToTerminal() const
cJSON * getBugDescription() const
PartialLeakBug(const EventStack &bugEventStack)
static bool classof(const GenericBug *bug)
ClassOf.
static bool classof(const GenericBug *bug)
ClassOf.
PartialNullPtrDereferenceBug(const EventStack &bugEventStack)
virtual const std::string getEventLoc() const
virtual const std::string getEventDescription() const
SVFBugEvent(u32_t typeAndInfoFlag, const ICFGNode *eventInst)
u32_t getEventType() const
const ICFGNode * eventInst
virtual const std::string getFuncName() const
virtual ~SVFBugEvent()=default
const BugSet & getBugSet() const
void addAbsExecBug(GenericBug::BugType bugType, const GenericBug::EventStack &eventStack, s64_t allocLowerBound, s64_t allocUpperBound, s64_t accessLowerBound, s64_t accessUpperBound)
SVF::Set< const GenericBug * > BugSet
void setStat(double time, std::string mem, double coverage)
void dumpToJsonFile(const std::string &filePath) const
void addSaberBug(GenericBug::BugType bugType, const GenericBug::EventStack &eventStack)
SVFBugReport()=default
for isBitcode
Definition BasicTypes.h:70
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
llvm::Loop Loop
LLVM Loop.
Definition BasicTypes.h:147
unsigned u32_t
Definition GeneralType.h:67
signed long long s64_t
Definition GeneralType.h:70
Definition cJSON.h:104