Static Value-Flow Analysis
|
Detector for identifying buffer overflow issues. More...
#include <AEDetector.h>
Public Member Functions | |
BufOverflowDetector () | |
Constructor initializes the detector kind to BUF_OVERFLOW and sets up external API buffer overflow rules. | |
~BufOverflowDetector ()=default | |
Destructor. | |
void | updateGepObjOffsetFromBase (AddressValue gepAddrs, AddressValue objAddrs, IntervalValue offset) |
Updates the offset of a GEP object from its base. | |
void | detect (AbstractState &as, const ICFGNode *) |
Detect buffer overflow issues within a node. | |
void | handleStubFunctions (const CallICFGNode *) |
Handles external API calls related to buffer overflow detection. | |
void | addToGepObjOffsetFromBase (const GepObjVar *obj, const IntervalValue &offset) |
Adds an offset to a GEP object. | |
bool | hasGepObjOffsetFromBase (const GepObjVar *obj) const |
Checks if a GEP object has an associated offset. | |
IntervalValue | getGepObjOffsetFromBase (const GepObjVar *obj) const |
Retrieves the offset of a GEP object from its base. | |
IntervalValue | getAccessOffset (AbstractState &as, NodeID objId, const GepStmt *gep) |
Retrieves the access offset for a given object and GEP statement. | |
void | addBugToReporter (const AEException &e, const ICFGNode *node) |
Adds a bug to the reporter based on an exception. | |
void | reportBug () |
Reports all detected buffer overflow bugs. | |
void | initExtAPIBufOverflowCheckRules () |
Initializes external API buffer overflow check rules. | |
void | detectExtAPI (AbstractState &as, const CallICFGNode *call) |
Handles external API calls related to buffer overflow detection. | |
bool | canSafelyAccessMemory (AbstractState &as, const SVFVar *value, const IntervalValue &len) |
Checks if memory can be safely accessed. | |
Public Member Functions inherited from SVF::AEDetector | |
AEDetector () | |
Constructor initializes the detector kind to UNKNOWN. | |
virtual | ~AEDetector ()=default |
Virtual destructor for safe polymorphic use. | |
DetectorKind | getKind () const |
Get the kind of the detector. | |
Static Public Member Functions | |
static bool | classof (const AEDetector *detector) |
Check if the detector is of the BUF_OVERFLOW kind. | |
Static Public Member Functions inherited from SVF::AEDetector | |
static bool | classof (const AEDetector *detector) |
Check if the detector is of the UNKNOWN kind. | |
Private Member Functions | |
bool | detectStrcat (AbstractState &as, const CallICFGNode *call) |
Detects buffer overflow in 'strcat' function calls. | |
bool | detectStrcpy (AbstractState &as, const CallICFGNode *call) |
Detects buffer overflow in 'strcpy' function calls. | |
Private Attributes | |
Map< const GepObjVar *, IntervalValue > | gepObjOffsetFromBase |
Maps GEP objects to their offsets from the base. | |
Map< std::string, std::vector< std::pair< u32_t, u32_t > > > | extAPIBufOverflowCheckRules |
Rules for checking buffer overflows in external APIs. | |
Set< std::string > | bugLoc |
Set of locations where bugs have been reported. | |
SVFBugReport | recoder |
Recorder for abstract execution bugs. | |
Map< const ICFGNode *, std::string > | nodeToBugInfo |
Maps ICFG nodes to bug information. | |
Friends | |
class | AbstractInterpretation |
Additional Inherited Members | |
Public Types inherited from SVF::AEDetector | |
enum | DetectorKind { BUF_OVERFLOW , UNKNOWN } |
Enumerates the types of detectors available. More... | |
Protected Attributes inherited from SVF::AEDetector | |
DetectorKind | kind |
The kind of the detector. | |
Detector for identifying buffer overflow issues.
Definition at line 133 of file AEDetector.h.
|
inline |
Constructor initializes the detector kind to BUF_OVERFLOW and sets up external API buffer overflow rules.
Definition at line 140 of file AEDetector.h.
|
default |
Destructor.
|
inline |
Adds a bug to the reporter based on an exception.
e | The exception that was thrown. |
node | Pointer to the ICFG node where the bug was detected. |
Definition at line 232 of file AEDetector.h.
|
inline |
Adds an offset to a GEP object.
obj | Pointer to the GEP object. |
offset | The interval value of the offset. |
Definition at line 190 of file AEDetector.h.
bool BufOverflowDetector::canSafelyAccessMemory | ( | AbstractState & | as, |
const SVFVar * | value, | ||
const IntervalValue & | len | ||
) |
Checks if memory can be safely accessed.
Checks if a memory access is safe given a specific buffer length.
as | Reference to the abstract state. |
value | Pointer to the SVF var. |
len | The interval value representing the length of the memory access. |
This function ensures that a given memory access, starting at a specific value, does not exceed the allocated size of the buffer.
as | Reference to the abstract state. |
value | Pointer to the SVF var. |
len | The interval value representing the length of the memory access. |
Definition at line 456 of file AEDetector.cpp.
|
inlinestatic |
Check if the detector is of the BUF_OVERFLOW kind.
detector | Pointer to the detector. |
Definition at line 156 of file AEDetector.h.
|
virtual |
Detect buffer overflow issues within a node.
Detects buffer overflow issues within a given ICFG node.
as | Reference to the abstract state. |
node | Pointer to the ICFG node. |
This function handles both non-call nodes, where it analyzes GEP (GetElementPtr) instructions for potential buffer overflows, and call nodes, where it checks for external API calls that may cause overflows.
as | Reference to the abstract state. |
node | Pointer to the ICFG node. |
Implements SVF::AEDetector.
Definition at line 44 of file AEDetector.cpp.
void BufOverflowDetector::detectExtAPI | ( | AbstractState & | as, |
const CallICFGNode * | call | ||
) |
Handles external API calls related to buffer overflow detection.
as | Reference to the abstract state. |
call | Pointer to the call ICFG node. |
This function checks the type of external memory API (e.g., memcpy, memset, strcpy, strcat) and applies the corresponding buffer overflow checks based on predefined rules.
as | Reference to the abstract state. |
call | Pointer to the call ICFG node. |
Definition at line 220 of file AEDetector.cpp.
|
private |
Detects buffer overflow in 'strcat' function calls.
as | Reference to the abstract state. |
call | Pointer to the call ICFG node. |
This function checks if the destination buffer can safely accommodate both the existing string and the concatenated string from the source.
as | Reference to the abstract state. |
call | Pointer to the call ICFG node. |
Definition at line 415 of file AEDetector.cpp.
|
private |
Detects buffer overflow in 'strcpy' function calls.
as | Reference to the abstract state. |
call | Pointer to the call ICFG node. |
This function checks if the destination buffer can safely accommodate the source string being copied, accounting for the null terminator.
as | Reference to the abstract state. |
call | Pointer to the call ICFG node. |
Definition at line 397 of file AEDetector.cpp.
IntervalValue BufOverflowDetector::getAccessOffset | ( | SVF::AbstractState & | as, |
SVF::NodeID | objId, | ||
const GepStmt * | gep | ||
) |
Retrieves the access offset for a given object and GEP statement.
as | Reference to the abstract state. |
objId | The ID of the object. |
gep | Pointer to the GEP statement. |
This function calculates the access offset for a base object or a sub-object of an aggregate object (using GEP). If the object is a dummy object, it returns a top interval value.
as | Reference to the abstract state. |
objId | The ID of the object. |
gep | Pointer to the GEP statement. |
Definition at line 314 of file AEDetector.cpp.
|
inline |
Retrieves the offset of a GEP object from its base.
obj | Pointer to the GEP object. |
Definition at line 210 of file AEDetector.h.
|
virtual |
Handles external API calls related to buffer overflow detection.
Handles stub functions within the ICFG node.
call | Pointer to the call ICFG node. |
This function is a placeholder for handling stub functions within the ICFG node.
node | Pointer to the ICFG node. |
Implements SVF::AEDetector.
Definition at line 114 of file AEDetector.cpp.
Checks if a GEP object has an associated offset.
obj | Pointer to the GEP object. |
Definition at line 200 of file AEDetector.h.
void BufOverflowDetector::initExtAPIBufOverflowCheckRules | ( | ) |
Initializes external API buffer overflow check rules.
This function sets up rules for various memory-related functions like memcpy, memset, etc., defining which arguments should be checked for buffer overflows.
Definition at line 186 of file AEDetector.cpp.
|
inlinevirtual |
Reports all detected buffer overflow bugs.
Implements SVF::AEDetector.
Definition at line 264 of file AEDetector.h.
void BufOverflowDetector::updateGepObjOffsetFromBase | ( | SVF::AddressValue | gepAddrs, |
SVF::AddressValue | objAddrs, | ||
SVF::IntervalValue | offset | ||
) |
Updates the offset of a GEP object from its base.
gepAddrs | Address value for GEP. |
objAddrs | Address value for the object. |
offset | The interval value of the offset. |
This function calculates and stores the offset of a GEP object from its base object using the addresses and offsets provided.
gepAddrs | The addresses of the GEP objects. |
objAddrs | The addresses of the base objects. |
offset | The interval value of the offset. |
Definition at line 346 of file AEDetector.cpp.
|
friend |
Definition at line 135 of file AEDetector.h.
|
private |
Set of locations where bugs have been reported.
Definition at line 319 of file AEDetector.h.
|
private |
Rules for checking buffer overflows in external APIs.
Definition at line 318 of file AEDetector.h.
|
private |
Maps GEP objects to their offsets from the base.
Definition at line 317 of file AEDetector.h.
Maps ICFG nodes to bug information.
Definition at line 321 of file AEDetector.h.
|
private |
Recorder for abstract execution bugs.
Definition at line 320 of file AEDetector.h.