Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions resolve-cveassert/src/CVEAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct LabelCVEPass : public PassInfoMixin<LabelCVEPass> {
std::vector<Vulnerability> vulnerabilities;

enum VulnID {
ALL = 0,
STACK_BASED_BUF_OVERFLOW = 121,
HEAP_BASED_BUF_OVERFLOW = 122,
WRITE_WHAT_WHERE = 123,
Expand Down Expand Up @@ -174,6 +175,15 @@ struct LabelCVEPass : public PassInfoMixin<LabelCVEPass> {
}
}

void applyAutomaticSanitizers(Function &F, Vulnerability::RemediationStrategies strategy) {
/// applies all automatic sanitizers (operation masking excluded)
sanitizeFreeOfNonHeap(&F, strategy);
sanitizeMemInstBounds(&F, strategy);
sanitizeNullPointers(&F, strategy);
sanitizeDivideByZero(&F, strategy);
sanitizeIntOverflow(&F, strategy);
}

/// For each function, if it matches the target function name, insert calls to
/// the vulnerability handlers as specified in the JSON. Each call receives
/// the triggering argument parsed from the JSON.
Expand Down Expand Up @@ -259,6 +269,11 @@ struct LabelCVEPass : public PassInfoMixin<LabelCVEPass> {
result = PreservedAnalyses::none();
break;

case VulnID::ALL:
applyAutomaticSanitizers(F, vuln.Strategy);
result = PreservedAnalyses::none();
break;

default:
errs() << "[CVEAssert] Error: CWE " << vuln.WeaknessID
<< " not implemented\n";
Expand Down
6 changes: 3 additions & 3 deletions resolve-cveassert/src/Vulnerability.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ struct Vulnerability {
return std::nullopt;
}

auto vulnType = jsonObj->getString("cwe-id");
if (!vulnType) {
auto vulnID = jsonObj->getString("cwe-id");
if (!vulnID) {
llvm::errs() << "[CVEAssert] Error: No 'cwe-id' field found in JSON.\n";
return std::nullopt;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ struct Vulnerability {

Vulnerability vuln{
targetFile->str(), targetFunction->str(),
static_cast<uint32_t>(std::stoi(vulnType->str())),
static_cast<uint32_t>(std::stoi(vulnID->str())),
undesirableFunction, strategy,
};
return std::make_optional(vuln);
Expand Down