|
Static Value-Flow Analysis
|
Handles external API calls and manages abstract states. More...
#include <AbsExtAPI.h>
Public Types | |
| enum | ExtAPIType { UNCLASSIFIED , MEMCPY , MEMSET , STRCPY , STRCAT } |
| Enumeration of external API types. More... | |
Public Member Functions | |
| void | initExtFunMap () |
| Initializes the external function map. | |
| std::string | strRead (const ValVar *rhs, const ICFGNode *node) |
| Reads a string from the abstract state. | |
| void | handleExtAPI (const CallICFGNode *call) |
| Handles an external API call. | |
| u32_t | getElementSize (const ValVar *var) |
| Get the byte size of each element for a pointer/array variable. | |
| u32_t | getStringElementSize (const ValVar *var, const ICFGNode *node) |
| Scalar integer width of the pointed-to base object; zero if unknown. | |
| IntervalValue | getStringLastByte (const CallICFGNode *call, const IntervalValue &length) |
| Last byte offset written for length elements plus the terminator. | |
| IntervalValue | getStrncatLength (const CallICFGNode *call) |
| Elements strncat appends: min(n, strlen(src)). | |
| void | handleStringCopy (const CallICFGNode *call, const IntervalValue &length, const IntervalValue &start) |
| Write length source elements and a NUL into dst at element start. | |
| IntervalValue | getStrlen (const ValVar *strValue, const ICFGNode *node) |
| String length in elements, excluding NUL; an unproved end is unbounded. | |
| void | handleStrcpy (const CallICFGNode *call) |
| void | handleStrcat (const CallICFGNode *call) |
| void | handleStrncat (const CallICFGNode *call) |
| void | handleMemcpy (const ValVar *dst, const ValVar *src, const IntervalValue &len, u32_t start_idx, const ICFGNode *node) |
| Core memcpy: copy len bytes from src to dst starting at dst[start_idx]. | |
| void | handleMemset (const ValVar *dst, const IntervalValue &elem, const IntervalValue &len, const ICFGNode *node) |
| IntervalValue | getRangeLimitFromType (const SVFType *type) |
| Gets the range limit from a type. | |
| AbstractState & | getAbsState (const ICFGNode *node) |
| Retrieves the abstract state from the trace for a given ICFG node. | |
| void | collectCheckPoint () |
| void | checkPointAllSet () |
Static Public Member Functions | |
| static bool | isValidLength (const IntervalValue &len) |
| Check if an interval length is usable (not bottom, not unbounded). | |
| static u32_t | getBoundedMinimumByteCount (const IntervalValue &len) |
| Return the lower bound of len, capped by the field limit. | |
Public Attributes | |
| Set< const CallICFGNode * > | checkpoints |
Protected Attributes | |
| AbstractInterpretation * | ae |
| Owning AbstractInterpretation; provides state access. | |
| PAG * | pag |
| Pointer to the SVF intermediate representation. | |
| ICFG * | icfg |
| Pointer to the interprocedural control flow graph. | |
| Map< std::string, std::function< void(const CallICFGNode *)> > | func_map |
| Map of function names to handlers. | |
Private Member Functions | |
| AbsExtAPI (AbstractInterpretation *ae) | |
| Constructor for AbsExtAPI. | |
Friends | |
| class | AbstractInterpretation |
Handles external API calls and manages abstract states.
Definition at line 48 of file AbsExtAPI.h.
Enumeration of external API types.
| Enumerator | |
|---|---|
| UNCLASSIFIED | |
| MEMCPY | |
| MEMSET | |
| STRCPY | |
| STRCAT | |
Definition at line 55 of file AbsExtAPI.h.
|
private |
Constructor for AbsExtAPI.
| ae | Reference to the AbstractInterpretation instance. |
Definition at line 35 of file AbsExtAPI.cpp.
| void AbsExtAPI::checkPointAllSet | ( | ) |
Definition at line 293 of file AbsExtAPI.cpp.
| void AbsExtAPI::collectCheckPoint | ( | ) |
Definition at line 253 of file AbsExtAPI.cpp.
| AbstractState & AbsExtAPI::getAbsState | ( | const ICFGNode * | node | ) |
Retrieves the abstract state from the trace for a given ICFG node.
| node | Pointer to the ICFG node. |
| Assertion | if no trace exists for the node. |
Definition at line 248 of file AbsExtAPI.cpp.
|
static |
Return the lower bound of len, capped by the field limit.
Definition at line 424 of file AbsExtAPI.cpp.
Get the byte size of each element for a pointer/array variable.
Get the byte size of each element for a pointer/array variable. Shared by handleMemcpy, handleMemset, and getStrlen to avoid duplication.
Definition at line 403 of file AbsExtAPI.cpp.
| IntervalValue AbsExtAPI::getRangeLimitFromType | ( | const SVFType * | type | ) |
Gets the range limit from a type.
| type | Pointer to the SVF type. |
This function, getRangeLimitFromType, calculates the lower and upper bounds of a numeric range for a given SVFType. It is used to determine the possible value range of integer types. If the type is an SVFIntegerType, it calculates the bounds based on the size and signedness of the type. The calculated bounds are returned as an IntervalValue representing the lower (lb) and upper (ub) limits of the range.
| type | The SVFType for which to calculate the value range. |
Definition at line 720 of file AbsExtAPI.cpp.
Scalar integer width of the pointed-to base object; zero if unknown.
Definition at line 435 of file AbsExtAPI.cpp.
| IntervalValue AbsExtAPI::getStringLastByte | ( | const CallICFGNode * | call, |
| const IntervalValue & | length ) |
Last byte offset written for length elements plus the terminator.
Definition at line 457 of file AbsExtAPI.cpp.
| IntervalValue AbsExtAPI::getStrlen | ( | const ValVar * | strValue, |
| const ICFGNode * | node ) |
String length in elements, excluding NUL; an unproved end is unbounded.
String length in elements, read from the abstract state only. Lower bound: leading elements whose abstract value excludes 0; it stops at the first element that may be 0 (unknown, uninitialized, pointer, or a range containing 0), so uncertainty only weakens it. Upper bound: an element that is exactly 0; without one the length is unbounded above. The scan budget is not a termination guarantee.
Definition at line 479 of file AbsExtAPI.cpp.
| IntervalValue AbsExtAPI::getStrncatLength | ( | const CallICFGNode * | call | ) |
Elements strncat appends: min(n, strlen(src)).
Definition at line 565 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleExtAPI | ( | const CallICFGNode * | call | ) |
Handles an external API call.
| call | Pointer to the call ICFG node. |
Definition at line 332 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleMemcpy | ( | const ValVar * | dst, |
| const ValVar * | src, | ||
| const IntervalValue & | len, | ||
| u32_t | start_idx, | ||
| const ICFGNode * | node ) |
Core memcpy: copy len bytes from src to dst starting at dst[start_idx].
Definition at line 632 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleMemset | ( | const ValVar * | dst, |
| const IntervalValue & | elem, | ||
| const IntervalValue & | len, | ||
| const ICFGNode * | node ) |
Core memset: fill dst with elem for len bytes. Note: elemSize here uses the pointee type's full size (not array element size) to match how LLVM memset/wmemset intrinsics measure len. For a pointer to wchar_t[100], elemSize = sizeof(wchar_t[100]), so range_val reflects the number of top-level GEP fields, not individual array elements.
Definition at line 667 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleStrcat | ( | const CallICFGNode * | call | ) |
strcat(dst, src): append all of src after the end of dst. Covers: strcat, __strcat_chk, wcscat, __wcscat_chk
Definition at line 546 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleStrcpy | ( | const CallICFGNode * | call | ) |
strcpy(dst, src): copy all of src (including '\0') into dst. Covers: strcpy, __strcpy_chk, stpcpy, wcscpy, __wcscpy_chk
Definition at line 537 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleStringCopy | ( | const CallICFGNode * | call, |
| const IntervalValue & | length, | ||
| const IntervalValue & | start ) |
Write length source elements and a NUL into dst at element start.
Definition at line 574 of file AbsExtAPI.cpp.
| void AbsExtAPI::handleStrncat | ( | const CallICFGNode * | call | ) |
strncat(dst, src, n): append at most n elements after the end of dst. Covers: strncat, __strncat_chk, wcsncat, __wcsncat_chk
Definition at line 557 of file AbsExtAPI.cpp.
| void AbsExtAPI::initExtFunMap | ( | ) |
Initializes the external function map.
Definition at line 42 of file AbsExtAPI.cpp.
|
static |
Check if an interval length is usable (not bottom, not unbounded).
Check if an interval length is usable for memory operations. Returns false for bottom (no information) or unbounded lower bound (cannot determine a concrete start for iteration).
Definition at line 419 of file AbsExtAPI.cpp.
Reads a string from the abstract state.
| as | Reference to the abstract state. |
| rhs | Pointer to the SVF variable representing the string. |
Definition at line 304 of file AbsExtAPI.cpp.
|
friend |
Definition at line 61 of file AbsExtAPI.h.
|
protected |
Owning AbstractInterpretation; provides state access.
Definition at line 142 of file AbsExtAPI.h.
| Set<const CallICFGNode*> SVF::AbsExtAPI::checkpoints |
Definition at line 139 of file AbsExtAPI.h.
|
protected |
Map of function names to handlers.
Definition at line 145 of file AbsExtAPI.h.
|
protected |
Pointer to the interprocedural control flow graph.
Definition at line 144 of file AbsExtAPI.h.
|
protected |
Pointer to the SVF intermediate representation.
Definition at line 143 of file AbsExtAPI.h.