Skip to content

Commit

Permalink
SVF code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
yuleisui committed Aug 26, 2024
1 parent ce50dd0 commit 581cdbc
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 99 deletions.
52 changes: 34 additions & 18 deletions svf/include/AE/Svfexe/AEDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class AEDetector
* @enum DetectorKind
* @brief Enumerates the types of detectors available.
*/
enum DetectorKind {
enum DetectorKind
{
BUF_OVERFLOW, ///< Detector for buffer overflow issues.
UNKNOWN, ///< Default type if the kind is not specified.
};
Expand Down Expand Up @@ -96,7 +97,8 @@ class AEDetector
* @class AEException
* @brief Exception class for handling errors in Abstract Execution.
*/
class AEException : public std::exception {
class AEException : public std::exception
{
public:
/**
* @brief Constructor initializes the exception with a message.
Expand All @@ -109,7 +111,8 @@ class AEException : public std::exception {
* @brief Provides the error message.
* @return The error message as a C-string.
*/
virtual const char* what() const throw() {
virtual const char* what() const throw()
{
return msg_.c_str();
}

Expand All @@ -128,7 +131,8 @@ class BufOverflowDetector : public AEDetector
/**
* @brief Constructor initializes the detector kind to BUF_OVERFLOW and sets up external API buffer overflow rules.
*/
BufOverflowDetector() {
BufOverflowDetector()
{
kind = BUF_OVERFLOW;
initExtAPIBufOverflowCheckRules();
}
Expand Down Expand Up @@ -170,7 +174,8 @@ class BufOverflowDetector : public AEDetector
* @param obj Pointer to the GEP object.
* @param offset The interval value of the offset.
*/
void addToGepObjOffsetFromBase(const GepObjVar* obj, const IntervalValue& offset) {
void addToGepObjOffsetFromBase(const GepObjVar* obj, const IntervalValue& offset)
{
gepObjOffsetFromBase[obj] = offset;
}

Expand All @@ -179,7 +184,8 @@ class BufOverflowDetector : public AEDetector
* @param obj Pointer to the GEP object.
* @return True if the GEP object has an offset, false otherwise.
*/
bool hasGepObjOffsetFromBase(const GepObjVar* obj) const {
bool hasGepObjOffsetFromBase(const GepObjVar* obj) const
{
return gepObjOffsetFromBase.find(obj) != gepObjOffsetFromBase.end();
}

Expand All @@ -188,7 +194,8 @@ class BufOverflowDetector : public AEDetector
* @param obj Pointer to the GEP object.
* @return The interval value of the offset.
*/
IntervalValue getGepObjOffsetFromBase(const GepObjVar* obj) const {
IntervalValue getGepObjOffsetFromBase(const GepObjVar* obj) const
{
if (hasGepObjOffsetFromBase(obj))
return gepObjOffsetFromBase.at(obj);
else
Expand All @@ -209,33 +216,39 @@ class BufOverflowDetector : public AEDetector
* @param e The exception that was thrown.
* @param node Pointer to the ICFG node where the bug was detected.
*/
void addBugToReporter(const AEException& e, const ICFGNode* node) {
void addBugToReporter(const AEException& e, const ICFGNode* node)
{
const SVFInstruction* inst = nullptr;

// Determine the instruction associated with the ICFG node
if (const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(node)) {
if (const CallICFGNode* call = SVFUtil::dyn_cast<CallICFGNode>(node))
{
inst = call->getCallSite(); // If the node is a call node, get the call site instruction
}
else {
else
{
inst = node->getSVFStmts().back()->getInst(); // Otherwise, get the last instruction of the node's
// statements
// statements
}

GenericBug::EventStack eventStack;
SVFBugEvent sourceInstEvent(SVFBugEvent::EventType::SourceInst, inst);
eventStack.push_back(sourceInstEvent); // Add the source instruction event to the event stack

if (eventStack.empty()) {
if (eventStack.empty())
{
return; // If the event stack is empty, return early
}

std::string loc = eventStack.back().getEventLoc(); // Get the location of the last event in the stack

// Check if the bug at this location has already been reported
if (bugLoc.find(loc) != bugLoc.end()) {
if (bugLoc.find(loc) != bugLoc.end())
{
return; // If the bug location is already reported, return early
}
else {
else
{
bugLoc.insert(loc); // Otherwise, mark this location as reported
}

Expand All @@ -247,12 +260,15 @@ class BufOverflowDetector : public AEDetector
/**
* @brief Reports all detected buffer overflow bugs.
*/
void reportBug() {
if (!nodeToBugInfo.empty()) {
void reportBug()
{
if (!nodeToBugInfo.empty())
{
std::cerr << "######################Buffer Overflow (" + std::to_string(nodeToBugInfo.size())
+ " found)######################\n";
+ " found)######################\n";
std::cerr << "---------------------------------------------\n";
for (const auto& it : nodeToBugInfo) {
for (const auto& it : nodeToBugInfo)
{
std::cerr << it.second << "\n---------------------------------------------\n";
}
}
Expand Down
8 changes: 5 additions & 3 deletions svf/include/AE/Svfexe/AbstractInterpretation.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ class AbstractInterpretation
/// Program entry
void analyse();

static AbstractInterpretation& getAEInstance() {
static AbstractInterpretation& getAEInstance()
{
static AbstractInterpretation instance;
return instance;
}

void addDetector(std::unique_ptr<AEDetector> detector) {
void addDetector(std::unique_ptr<AEDetector> detector)
{
detectors.push_back(std::move(detector));
}

Expand Down Expand Up @@ -360,7 +362,7 @@ class AbstractInterpretation
Set<const CallICFGNode*> checkpoints;
Set<std::string> checkpoint_names;
Map<const ICFGNode*, AbstractState>
abstractTrace; // abstract states immediately after nodes
abstractTrace; // abstract states immediately after nodes
std::string moduleName;

std::vector<std::unique_ptr<AEDetector>> detectors;
Expand Down
Loading

0 comments on commit 581cdbc

Please sign in to comment.