Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taint Config Serialization #20

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f63b6dc
LLVMTaintConfigYAML class
mxHuber Jul 3, 2023
77d35cd
basic structure
mxHuber Jul 3, 2023
e8b1276
beginning of restructuring
mxHuber Jul 6, 2023
7bf384f
compiles, untested
mxHuber Jul 19, 2023
4b8d770
Constructor init
mxHuber Jul 19, 2023
b1f3d81
minor bug fixes
mxHuber Jul 21, 2023
d51bd3a
new start w better approach
mxHuber Jul 25, 2023
e6e2c30
basic working version
mxHuber Jul 27, 2023
8ce7a13
removed unneccesary includes and functions
mxHuber Jul 27, 2023
135a2b7
new TaintConfigData structure
mxHuber Aug 4, 2023
4ed0efd
fully refactored, doesn't compile
mxHuber Aug 4, 2023
39c1ca2
added func/var structs
mxHuber Aug 17, 2023
595d313
compiling version, tests fail
mxHuber Aug 18, 2023
986eabb
only 3 unittests fail now
mxHuber Aug 24, 2023
3a2909a
fixed a bug with sink values causing a crash
mxHuber Aug 24, 2023
0c83170
all unittests pass
mxHuber Aug 25, 2023
7cba280
review fixes
mxHuber Sep 4, 2023
36a43ef
one faulty unittest remaining
mxHuber Sep 4, 2023
6427805
all unittests pass + myphasartool revert
mxHuber Sep 5, 2023
d072b6b
pre-commit stuff
mxHuber Sep 6, 2023
69fb508
review changes + unittest fixed
mxHuber Sep 6, 2023
d1561ec
added static to handle functions
mxHuber Sep 8, 2023
3d826af
Merge branch 'development' into f-TaintConfigSerialization
mxHuber Sep 13, 2023
6fb5b30
cleanup
fabianbs96 Sep 30, 2023
f6acc3c
minor
fabianbs96 Sep 30, 2023
27bb560
Pin swift version
fabianbs96 Sep 30, 2023
e2b506a
Remove unnecessary forward declaration
fabianbs96 Oct 2, 2023
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
5 changes: 3 additions & 2 deletions include/phasar/PhasarLLVM/TaintConfig/LLVMTaintConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace psr {
class LLVMTaintConfig;
class LLVMProjectIRDB;
class TaintConfigData;

template <> struct TaintConfigTraits<LLVMTaintConfig> {
using n_t = const llvm::Instruction *;
Expand All @@ -31,7 +32,7 @@ class LLVMTaintConfig : public TaintConfigBase<LLVMTaintConfig> {

public:
explicit LLVMTaintConfig(const psr::LLVMProjectIRDB &Code,
const nlohmann::json &Config);
const psr::TaintConfigData &Config);
explicit LLVMTaintConfig(const psr::LLVMProjectIRDB &AnnotatedCode);
explicit LLVMTaintConfig(
TaintDescriptionCallBackTy SourceCB, TaintDescriptionCallBackTy SinkCB,
Expand Down Expand Up @@ -93,7 +94,7 @@ class LLVMTaintConfig : public TaintConfigBase<LLVMTaintConfig> {
// --- utilities

void addAllFunctions(const LLVMProjectIRDB &IRDB,
const nlohmann::json &Config);
const TaintConfigData &Config);

// --- data members

Expand Down
7 changes: 3 additions & 4 deletions include/phasar/PhasarLLVM/TaintConfig/TaintConfigBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
#ifndef PHASAR_PHASARLLVM_TAINTCONFIG_TAINTCONFIGBASE_H
#define PHASAR_PHASARLLVM_TAINTCONFIG_TAINTCONFIGBASE_H

#include "phasar/PhasarLLVM/TaintConfig/TaintConfigData.h"
#include "phasar/Utils/Nullable.h"

#include "llvm/ADT/FunctionExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"

#include "nlohmann/json.hpp"

#include <map>
#include <set>
#include <type_traits>
Expand Down Expand Up @@ -159,8 +158,8 @@ template <typename Derived> class TaintConfigBase {
//===----------------------------------------------------------------------===//
// Miscellaneous helper functions

nlohmann::json parseTaintConfig(const llvm::Twine &Path);
std::optional<nlohmann::json> parseTaintConfigOrNull(const llvm::Twine &Path);
TaintConfigData parseTaintConfig(const llvm::Twine &Path);
std::optional<TaintConfigData> parseTaintConfigOrNull(const llvm::Twine &Path);
fabianbs96 marked this conversation as resolved.
Show resolved Hide resolved

} // namespace psr

Expand Down
47 changes: 47 additions & 0 deletions include/phasar/PhasarLLVM/TaintConfig/TaintConfigData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/******************************************************************************
* Copyright (c) 2023 Fabian Schiebel.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of LICENSE.txt.
*
* Contributors:
* Maximilian Leo Huber and others
*****************************************************************************/

#ifndef PHASAR_PHASARLLVM_TAINTCONFIG_TAINTCONFIGDATA_H
#define PHASAR_PHASARLLVM_TAINTCONFIG_TAINTCONFIGDATA_H

#include <string>
#include <vector>

namespace psr {
struct TaintConfigData;
class LLVMProjectIRDB;

struct FunctionData {
FunctionData() = default;

std::string Name;
std::string ReturnType;
std::vector<int> SourceValues;
std::vector<int> SinkValues;
std::vector<int> SanitizerValues;
bool HasAllSinkParam = false;
};

struct VariableData {
VariableData() = default;

size_t Line{};
std::string Name;
std::string Scope;
std::string Cat;
};

struct TaintConfigData {
std::vector<FunctionData> Functions;
std::vector<VariableData> Variables;
};

} // namespace psr

#endif // PHASAR_PHASARLLVM_TAINTCONFIG_TAINTCONFIGDATA_H
17 changes: 3 additions & 14 deletions lib/Controller/AnalysisController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h"
#include "phasar/PhasarLLVM/HelperAnalyses.h"
#include "phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h"
#include "phasar/PhasarLLVM/TaintConfig/TaintConfigData.h"
#include "phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h"
#include "phasar/Utils/NlohmannLogging.h"
#include "phasar/Utils/Utilities.h"

#include "llvm/ADT/STLExtras.h"
Expand Down Expand Up @@ -185,10 +185,6 @@ void AnalysisController::emitRequestedHelperAnalysisResults() {
WithResultFileOrStdout("/psr-cg.txt",
[this](auto &OS) { HA.getICFG().print(OS); });
}
if (EmitterOptions & AnalysisControllerEmitterOptions::EmitCGAsJson) {
WithResultFileOrStdout(
"/psr-cg.json", [this](auto &OS) { OS << HA.getICFG().getAsJson(); });
}

if (EmitterOptions &
(AnalysisControllerEmitterOptions::EmitStatisticsAsJson |
Expand All @@ -198,11 +194,6 @@ void AnalysisController::emitRequestedHelperAnalysisResults() {
GeneralStatisticsAnalysis GSA;
const auto &Stats = GSA.runOnModule(*IRDB.getModule());

if (EmitterOptions &
AnalysisControllerEmitterOptions::EmitStatisticsAsText) {
llvm::outs() << Stats << '\n';
}

if (EmitterOptions &
AnalysisControllerEmitterOptions::EmitStatisticsAsJson) {
WithResultFileOrStdout("/psr-IrStatistics.json",
Expand All @@ -214,10 +205,8 @@ void AnalysisController::emitRequestedHelperAnalysisResults() {
LLVMTaintConfig AnalysisController::makeTaintConfig() {
std::string AnalysisConfigPath =
!AnalysisConfigs.empty() ? AnalysisConfigs[0] : "";
return !AnalysisConfigPath.empty()
? LLVMTaintConfig(HA.getProjectIRDB(),
parseTaintConfig(AnalysisConfigPath))
: LLVMTaintConfig(HA.getProjectIRDB());

return LLVMTaintConfig(HA.getProjectIRDB());
fabianbs96 marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace psr
2 changes: 0 additions & 2 deletions lib/PhasarLLVM/TaintConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ set(PHASAR_LINK_LIBS
phasar_db
phasar_llvm_db
phasar_llvm_utils
phasar_controlflow
phasar_llvm_controlflow
)

set(LLVM_LINK_COMPONENTS
Expand Down
Loading