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

Analyse real-world systems #85

Merged
merged 50 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6bb39d2
Refactor - Extract configuration attributes
fea-devteam May 9, 2022
4035bb9
Refactor - Replace temp with Query
fea-devteam May 9, 2022
c0377b5
Refactor - Fix ToolFactory path issue
fea-devteam May 9, 2022
4d3de8c
Refactor - Extract tasks
fea-devteam May 11, 2022
0b9e89d
Enhance console output with own logger
fea-devteam May 13, 2022
4a33935
Enhance console output, redirect all the current info into the log fi…
fea-devteam May 16, 2022
7e7ae95
Create validation folder, #72
fea-devteam May 16, 2022
ae08f37
Merge branch 'FrontEndART:main' into framework-repair
fea-devteam May 17, 2022
351441b
Enhance console output #45
fea-devteam May 17, 2022
3fbb3aa
Merge remote-tracking branch 'FrontEndART/main' into refactor
fea-devteam May 21, 2022
550817e
Refactor - Parameterize Function
fea-devteam May 21, 2022
1b3ff8e
Refactor - Extract Function
fea-devteam May 21, 2022
5cb02e6
Minor format changes #45
fea-devteam May 21, 2022
4013ec9
Merge branch 'refactor' into framework-repair
fea-devteam May 21, 2022
05e5f24
Minor format changes #45
fea-devteam May 22, 2022
2831ab5
Add support for Gradle #44
fea-devteam May 23, 2022
9377ed0
Add support for Ant #83
fea-devteam May 24, 2022
0a350c1
Add support for Ant #83
fea-devteam May 24, 2022
17bb84d
Merge remote-tracking branch 'origin/test-arduino' into test-arduino
fea-devteam May 30, 2022
fb0b29c
Find the variable name for some vulnerabilities
fea-devteam May 19, 2022
cd41e76
Column info on MS_SHOULD_BE_FINAL and EI_EXPOSE_REP2
fea-devteam May 24, 2022
ffbee5b
Complete refactor of ColumnInfoParser
fea-devteam May 24, 2022
f73a84d
Implement AST method for retrieving column info
fea-devteam May 24, 2022
b7d4d4e
Use JavaParser library for parsing column info (temporary solution)
fea-devteam May 27, 2022
68589f3
Extended JavaParser implementation, find column info for FB_EER/FB_Ei…
fea-devteam May 27, 2022
7e10346
dynamic column info data passed to OpenStaticAnalyzer and processed p…
fea-devteam May 27, 2022
9094838
ColumnInfoParser uses anonymous VoidVisitor class to visit nodes, min…
fea-devteam May 28, 2022
1b8d82f
Minor code cleanup
fea-devteam May 28, 2022
4d1bdaa
Insert TODOs
fea-devteam May 28, 2022
062cc43
Refactor - Replace temp with Query, minor changes
fea-devteam May 28, 2022
747cfbb
Refactor - SRP: Separate 'column info attach' from VulnerabilityLocation
fea-devteam May 28, 2022
068e0ae
Refactor - Clean OpenStaticAnalyzer
fea-devteam May 28, 2022
f42ed6f
Refactor - Clean OpenStaticAnalyzer
fea-devteam May 28, 2022
7fd96f8
Create integration test for: extracting column info #6
fea-devteam May 28, 2022
3a0f5c8
Framework repair (#77)
fea-devteam May 19, 2022
2992756
Refactor - Parameterize Function
fea-devteam May 21, 2022
bac5f06
Add support for Gradle #44
fea-devteam May 23, 2022
bef2c12
Refactor - Replace temp with Query, minor changes
fea-devteam May 28, 2022
a50d8ce
Refactor - SRP: Separate 'column info attach' from VulnerabilityLocation
fea-devteam May 28, 2022
4cd7505
Refactor - Clean OpenStaticAnalyzer
fea-devteam May 28, 2022
72e8eea
Fix NullPointerException in getResultPair()
fea-devteam Jun 1, 2022
293cbd1
Skip build when the generated patch is empty
fea-devteam Jun 1, 2022
3872abf
Log Vulnerabilities
fea-devteam Jun 1, 2022
1fae7ba
Add support for MavenCLI
fea-devteam Jun 3, 2022
444082c
Fix failure on not retrieved column info
fea-devteam Jun 3, 2022
35705b2
Merge remote-tracking branch 'FrontEndART/main' into framework-repair
fea-devteam Jun 3, 2022
6259109
Get mapping properties from config
fea-devteam Jun 3, 2022
7e2a8c0
Log elapsed time
fea-devteam Jun 3, 2022
10ffcea
Disable test case
fea-devteam Jun 3, 2022
d95bbc8
Create statistics
fea-devteam Jun 6, 2022
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Once the framework and the OpenStaticAnalyzer components are installed, you can

config.project_name=NAME OF THE PROJECT # e.g. test-project
config.project_path=ABSOLUTE PATH TO THE PROJECT SRC # e.g. d:\\AIFix4SecCode\\test-project
config.project_build_tool=NAME OF THE BUILD TOOL # maven / mavenCLI / gradle / ant
config.osa_path=PATH TO THE JAVA OPEN STATIC ANALYZER # e.g. d:\\OpenStaticAnalyzer-4.1.0-x64-Windows\\Java
config.osa_edition=ANALYZER EDITION # SourceMeter or OpenStaticAnalyzer
config.results_path=FOLDER TO PUT ANALYSIS RESULTS # e.g. d:\\AIFix4SecCode\\test-project\\results
Expand Down
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
</properties>

<dependencies>
<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-symbol-solver-core</artifactId>
<version>3.24.2</version>
</dependency>
<dependency>
<groupId>io.github.java-diff-utils</groupId>
<artifactId>java-diff-utils</artifactId>
Expand Down Expand Up @@ -70,6 +75,17 @@
<artifactId>coderepair</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>de.defmacro</groupId>
<artifactId>eclipse-astparser</artifactId>
<version>8.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
72 changes: 49 additions & 23 deletions src/main/java/eu/assuremoss/VulnRepairDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
import eu.assuremoss.framework.api.*;
import eu.assuremoss.framework.model.CodeModel;
import eu.assuremoss.framework.model.VulnerabilityEntry;
import eu.assuremoss.framework.modules.compiler.MavenPatchCompiler;
import eu.assuremoss.utils.*;
import eu.assuremoss.utils.factories.PatchCompilerFactory;
import eu.assuremoss.framework.modules.src.LocalSourceFolder;
import eu.assuremoss.utils.Configuration;
import eu.assuremoss.utils.MLogger;
import eu.assuremoss.utils.Pair;
import eu.assuremoss.utils.Utils;
import eu.assuremoss.utils.factories.ToolFactory;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
Expand All @@ -41,26 +38,35 @@
public class VulnRepairDriver {
private static final Logger LOG = LogManager.getLogger(VulnRepairDriver.class);
public static MLogger MLOG;
public static Properties properties;
private final PatchCompiler patchCompiler;
private final PathHandler path;
private final Statistics statistics;
private int patchCounter = 1;

public static void main(String[] args) throws IOException {
VulnRepairDriver driver = new VulnRepairDriver();
Configuration config = new Configuration(getConfigFile(args), getMappingFile(args));
VulnRepairDriver driver = new VulnRepairDriver(config.properties);

Utils.createDirectoryForResults(config.properties);
Utils.createDirectoryForValidation(config.properties);
Utils.createEmptyLogFile(config.properties);
driver.bootstrap(config.properties);
}

MLOG = new MLogger(config.properties, "log.txt");
public VulnRepairDriver(Properties properties) throws IOException {
this.patchCompiler = PatchCompilerFactory.getPatchCompiler(properties.getProperty(PROJECT_BUILD_TOOL_KEY));
this.path = new PathHandler(properties);
this.statistics = new Statistics(path);
VulnRepairDriver.properties = properties;

driver.bootstrap(config.properties);
initResourceFiles(properties);
MLOG = new MLogger(properties, "log.txt");
}

public void bootstrap(Properties props) {
MLOG.fInfo("Start!");

// 0. Setup
String currentTime = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
Date startTime = new Date();
String startTimeStr = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(startTime);

// 1. Get source code
MLOG.info("Project source acquiring started");
Expand All @@ -81,7 +87,7 @@ public void bootstrap(Properties props) {
// 3. Produces :- vulnerability locations
List<VulnerabilityEntry> vulnerabilityLocations = vulnDetector.getVulnerabilityLocations(scc.getSourceCodeLocation(), codeModels);
MLOG.info(String.format("Detected %d vulnerabilities", vulnerabilityLocations.size()));
vulnerabilityLocations.forEach(vulnEntry -> MLOG.fInfo(vulnEntry.getType() + " -> " + vulnEntry.getStartLine()));
statistics.saveVulnerabilityStatistics(props, vulnerabilityLocations);

// == Transform code / repair ==
Map<String, List<JSONObject>> problemFixMap = new HashMap<>();
Expand All @@ -90,28 +96,33 @@ public void bootstrap(Properties props) {
for (VulnerabilityEntry vulnEntry : vulnerabilityLocations) {
// - Init -
vulnIndex++;
PatchCompiler comp = new MavenPatchCompiler();

// - Skip if column info was not retrieved -
if (vulnEntry.getStartCol() == -1 && vulnEntry.getEndCol() == -1) {
MLOG.ninfo(String.format("No column info were retrieved, skipping vulnerability %d/%d", vulnIndex, vulnerabilityLocations.size()));
continue;
}

// - Generate repair patches -
MLOG.ninfo(String.format("Generating patches for %d/%d vulnerability", vulnIndex, vulnerabilityLocations.size()));
MLOG.ninfo(String.format("Generating patches for vulnerability %d/%d", vulnIndex, vulnerabilityLocations.size()));
List<Pair<File, Pair<Patch<String>, String>>> patches = vulnRepairer.generateRepairPatches(scc.getSourceCodeLocation(), vulnEntry, codeModels);

// - Applying & Compiling patches -
MLOG.info(String.format("Compiling patches for %d/%d vulnerability", vulnIndex, vulnerabilityLocations.size()));
List<Pair<File, Pair<Patch<String>, String>>> filteredPatches = comp.applyAndCompile(scc.getSourceCodeLocation(), patches, true);
MLOG.info(String.format("Compiling patches for vulnerability %d/%d", vulnIndex, vulnerabilityLocations.size()));
List<Pair<File, Pair<Patch<String>, String>>> filteredPatches = patchCompiler.applyAndCompile(scc.getSourceCodeLocation(), patches, true);

// - Testing Patches -
MLOG.info(String.format("Verifying patches for %d/%d vulnerability", vulnIndex, vulnerabilityLocations.size()));
List<Pair<File, Pair<Patch<String>, String>>> candidatePatches = getCandidatePatches(props, scc, vulnEntry, comp, filteredPatches);
MLOG.info(String.format("Verifying patches for vulnerability %d/%d", vulnIndex, vulnerabilityLocations.size()));
List<Pair<File, Pair<Patch<String>, String>>> candidatePatches = getCandidatePatches(props, scc, vulnEntry, patchCompiler, filteredPatches);

// - Save patches -
Utils.createDirectoryForPatches(props);
Utils.createDirectory(patchSavePath(props));
if (candidatePatches.isEmpty()) {
MLOG.info("No patch candidates were found, skipping!");
continue;
}

MLOG.info(String.format("Writing out patch candidates patches for %d/%d vulnerability", vulnIndex, vulnerabilityLocations.size()));
MLOG.info(String.format("Writing out candidate patches for vulnerability %d/%d", vulnIndex, vulnerabilityLocations.size()));
if (!problemFixMap.containsKey(vulnEntry.getType())) {
problemFixMap.put(vulnEntry.getType(), new ArrayList());
}
Expand All @@ -129,15 +140,19 @@ public void bootstrap(Properties props) {
}

if (archiveEnabled(props)) {
Utils.archiveResults(patchSavePath(props), props.getProperty(ARCHIVE_PATH), descriptionPath(props), currentTime);
Utils.archiveResults(patchSavePath(props), props.getProperty(ARCHIVE_PATH), descriptionPath(props), startTimeStr);
}

Utils.deleteIntermediatePatches(patchSavePath(props));
Utils.saveElapsedTime(startTime);
statistics.createResultStatistics(vulnerabilityLocations);

MLOG.info("Framework repair finished!");
}

private JSONObject getVSCodeConfig(Map<String, List<JSONObject>> problemFixMap) {
JSONObject vsCodeConfig = new JSONObject();
for(String problemType : problemFixMap.keySet()) {
for (String problemType : problemFixMap.keySet()) {
JSONArray fixesArray = new JSONArray();
fixesArray.addAll(problemFixMap.get(problemType));
vsCodeConfig.put(problemType, fixesArray);
Expand Down Expand Up @@ -219,4 +234,15 @@ private JSONObject generateFixEntity(Properties props, VulnerabilityEntry vulnEn
return issueObject;
}

/**
* Creates all resource files (directories, log files)
*
* @param props - a properties object that specifies the creation path of the files
*/
private static void initResourceFiles(Properties props) {
Utils.createDirectory(props.getProperty(RESULTS_PATH_KEY));
Utils.createDirectory(props.getProperty(VALIDATION_RESULTS_PATH_KEY));
Utils.createDirectory(String.valueOf(Paths.get(props.getProperty(RESULTS_PATH_KEY), "logs")));
Utils.createEmptyLogFile(props);
}
}
2 changes: 2 additions & 0 deletions src/main/java/eu/assuremoss/framework/api/PatchCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface PatchCompiler {
public void revertPatch(Pair<File, Patch<String>> patch, File srcLocation);

public void applyPatch(Pair<File, Patch<String>> patch, File srcLocation);

public String getBuildDirectoryName();
}
3 changes: 2 additions & 1 deletion src/main/java/eu/assuremoss/framework/model/CodeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum MODEL_TYPES {
EMBEDDING,
CFG,
OSA_GRAPH,
OSA_GRAPH_XML
OSA_GRAPH_XML,
FINDBUGS_XML
}

public CodeModel(MODEL_TYPES modelType, File codeModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@

import lombok.Data;

import java.io.Serializable;

@Data
public class VulnerabilityEntry {
public class VulnerabilityEntry implements Serializable {

/**
* Normal vulnerability name that is mapped with the magic name
*/
private String type;
/**
* Magic vulnerability name that should be converted to normal
*/
private String vulnType;
private String description;
private String path;
private String variable;
private int startLine;
private int endLine;
private int startCol;
private int endCol;

@Override
public String toString() {
return "VulnerabilityEntry\n" +
" type=" + type + '\n' +
" vulnType=" + vulnType + '\n' +
" description=" + description + '\n' +
" path=" + path + '\n' +
" variable=" + variable + '\n' +
" startLine=" + startLine + '\n' +
" endLine=" + endLine + '\n' +
" startCol=" + startCol + '\n' +
" endCol=" + endCol;
}

}
Loading