Skip to content

Commit

Permalink
Merge pull request #46 from jumormt/main
Browse files Browse the repository at this point in the history
update
  • Loading branch information
jumormt authored Jul 23, 2024
2 parents 8a66036 + 9d49d58 commit 94c05d9
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 120 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@ on:
repository_dispatch:
types: [ new-commit-from-SVF ]
jobs:
build:

docker-image-x86:
if: github.repository == 'SVF-tools/Teaching-Software-Analysis'
runs-on: ubuntu-latest

steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v2
-
name: Login to Docker Hub
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{secrets.DOCKER_USER}}
password: ${{secrets.DOCKER_PASSWD}}
-
name: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build and push

- name: Build and push x86 image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{secrets.DOCKER_USER}}/teaching-software-analysis:latest
platforms: linux/amd64
28 changes: 16 additions & 12 deletions .github/workflows/svf-teaching.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
env:
XCODE_VERSION: '15.3.0'
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
env:
XCODE_VERSION: '15.3.0'
steps:
# checkout the repo
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 18
# setup the environment

# setup the mac/ubuntu environment
- name: mac-setup
if: runner.os == 'macOS'
uses: maxim-lobanov/setup-xcode@v1
Expand All @@ -33,16 +33,20 @@ jobs:
sudo apt-get update
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install cmake gcc g++ nodejs doxygen graphviz
sudo apt-get install cmake gcc g++ nodejs doxygen graphviz lcov libncurses5-dev libtinfo5 libzstd-dev
# install llvm and svf
- name: env-setup
run: |
npm install svf-lib
# build current repo
- name: build-svf
# set SVF_DIR, LLVM_DIR and Z3_DIR and build
- name: build
run: |
source $GITHUB_WORKSPACE/env.sh
cmake .
make
export SVF_DIR=$(npm root)/SVF
export LLVM_DIR=$(npm root)/llvm-16.0.0.obj
export Z3_DIR=$(npm root)/z3.obj
echo "SVF_DIR="$SVF_DIR
echo "LLVM_DIR="$LLVM_DIR
echo "Z3_DIR="$Z3_DIR
cmake .
make
6 changes: 2 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
{
"name": "Linux",
"includePath": [
"/usr/include/**",
"/usr/local/include/**",
"/home/SVF-tools/SVF/**",
"${workspaceFolder}/**",
"/home/SVF-tools/SVF/llvm-16.0.0.obj/**"
"../SVF/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
Expand Down
23 changes: 7 additions & 16 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"name": "(debug) Launch",
"type": "cppdbg",
"request": "launch",
// Please change to executable of your working assignment e.g. Assignment-1: assign-1
"program": "${workspaceFolder}/bin/assign-1",
"args": [], // may input the test llvm bc file or other options may use
"stopAtEntry": false,
// Please change to the executable of your current lab or assignment
"program": "${workspaceFolder}/bin/hello",
"args": [], // may input the test llvm bc file or other options and flags the program may use
"cwd": "${workspaceFolder}",
"environment": [],
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: cpp build active file"
"preLaunchTask": "C/C++: cpp build active file",
"MIMode": "lldb"
}
]
}
}
5 changes: 2 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"label": "C/C++: cpp build active file",
"type": "shell",
// if you run SVF-Teaching not in docker container, you need to change the LLVM_DIR and SVF_DIR
"command": "cmake -DCMAKE_BUILD_TYPE=Debug -DSVF_DIR=/home/SVF-tools/SVF -DLLVM_DIR=/home/SVF-tools/SVF/llvm-16.0.0.obj -DZ3_DIR=/home/SVF-tools/SVF/z3.obj . && make",
"command": "cmake -DCMAKE_BUILD_TYPE=Debug -DSVF_DIR=../SVF -DLLVM_DIR=../SVF/llvm-16.0.0.obj -DZ3_DIR=../SVF/z3.obj . && make",
"options": {
"cwd": "${workspaceFolder}"
},
Expand All @@ -16,5 +16,4 @@
}
],
"version": "2.0.0"
}

}
11 changes: 4 additions & 7 deletions Assignment-2/Assignment-2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,16 @@ using namespace std;

/// TODO: print each path once this method is called, and
/// add each path as a string into std::set<std::string> paths
/// Print the path in the format "START: 1->2->4->5->END", where -> indicate an ICFGEdge connects two ICFGNode IDs
/// Print the path in the format "START->1->2->4->5->END", where -> indicate an ICFGEdge connects two ICFGNode IDs

void ICFGTraversal::printICFGPath(std::vector<const ICFGNode *> &path)
{


void ICFGTraversal::collectICFGPath(std::vector<unsigned> &path){

}


/// TODO: Implement your context-sensitive ICFG traversal here to traverse each program path (once for any loop) from src to dst
void ICFGTraversal::DFS(std::set<const ICFGNode *> &visited, std::vector<const ICFGNode *> &path, std::stack<const SVFInstruction*> &callstack, const ICFGNode *src, const ICFGNode *dst)
void ICFGTraversal::reachability(const ICFGNode *src, const ICFGNode *dst)
{


}
}
21 changes: 14 additions & 7 deletions Assignment-2/Assignment-2.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- Software-Analysis-Teaching Assignment 2-------------------------------------//
//===- SVF-Teaching Assignment 2-------------------------------------//
//
// SVF: Static Value-Flow Analysis Framework for Source Code
//
Expand All @@ -22,7 +22,7 @@
/*
// Software-Analysis-Teaching Assignment 2 : Source Sink ICFG DFS Traversal
//
//
//
*/
#ifndef ASSIGNMENT_2_H_
#define ASSIGNMENT_2_H_
Expand All @@ -33,17 +33,19 @@ using namespace SVF;

class ICFGTraversal
{
public:
typedef std::vector<const SVFInstruction*> CallStack;

public:

ICFGTraversal(SVFIR *p) : pag(p) {}

/// TODO: to be implemented
virtual void printICFGPath(std::vector<const ICFGNode *> &path);
virtual void collectICFGPath(std::vector<unsigned> &path);

/// TODO: to be implemented context sensitive DFS
void DFS(std::set<const ICFGNode *> &visited, std::vector<const ICFGNode *> &path, std::stack<const SVFInstruction *> &callstack, const ICFGNode *src, const ICFGNode *dst);
void reachability(const ICFGNode *src, const ICFGNode *dst);

// Identify source nodes on ICFG (i.e., call instruction with its callee function named 'src')
virtual std::set<const CallICFGNode *> &identifySources()
{
Expand Down Expand Up @@ -78,8 +80,13 @@ class ICFGTraversal
protected:
std::set<const CallICFGNode *> sources;
std::set<const CallICFGNode *> sinks;
Set<std::pair<const ICFGNode*, CallStack>> visited;
CallStack callstack;

SVFIR* pag;
std::set<std::string> paths;
SVFIR *pag;
std::vector<unsigned> path;

};

#endif
#endif
14 changes: 4 additions & 10 deletions Assignment-2/Test2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,15 @@ void Test1()
ICFG *icfg = pag->getICFG();
// If you want to test your own case, plase change the dump name
icfg->dump("./Assignment-2/testcase/dot/test1.ll.icfg");
std::vector<const ICFGNode *> path;
std::stack<const SVFInstruction *>callstack;
std::set<const ICFGNode *> visited;
ICFGTraversal *gt = new ICFGTraversal(pag);
for (const CallICFGNode *src : gt->identifySources())
{
for (const CallICFGNode *snk : gt->identifySinks())
{
gt->DFS(visited, path, callstack, src, snk);
gt->reachability(src, snk);
}
}
std::set<std::string> expected = {"START: 16->1->2->END"};
std::set<std::string> expected = {"START->16->1->2->END"};
assert(expected == gt->getPaths() && "test1 failed!");
std::cout << "test1 passed!" << "\n";
SVFIR::releaseSVFIR();
Expand All @@ -74,19 +71,16 @@ void Test2()
ICFG *icfg = pag->getICFG();
// If you want to test your own case, plase change the dump name
icfg->dump("./Assignment-2/testcase/dot/test2.ll.icfg");
std::vector<const ICFGNode *> path;
std::set<const ICFGNode *> visited;
std::stack<const SVFInstruction *>callstack;
ICFGTraversal *gt = new ICFGTraversal(pag);
for (const CallICFGNode *src : gt->identifySources())
{
for (const CallICFGNode *snk : gt->identifySinks())
{
gt->DFS(visited, path, callstack, src, snk);
gt->reachability(src, snk);
}
}

std::set<std::string> expected = {"START: 5->6->7->8->11->1->2->3->12->15->END", "START: 5->6->7->8->9->1->2->3->10->13->END"};
std::set<std::string> expected = {"START->5->6->7->8->11->1->2->3->12->15->END", "START->5->6->7->8->9->1->2->3->10->13->END"};
assert(expected == gt->getPaths() && "test2 failed!");
std::cout << "test2 passed!" << "\n";
LLVMModuleSet::releaseLLVMModuleSet();
Expand Down
11 changes: 5 additions & 6 deletions Assignment-3/Assignment-3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ using namespace std;

// TODO: Implement your Andersen's Algorithm here
void AndersenPTA::solveWorklist(){
processAllAddr();
processAllAddr();

// Keep solving until workList is empty.
while (!isWorklistEmpty())
{

}
// Keep solving until workList is empty.
while (!isWorklistEmpty()) {

}

}

Expand Down
8 changes: 3 additions & 5 deletions Assignment-4/Assignment-4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ void TaintGraphTraversal::taintChecking(){
ander->analyze();
for(const CallICFGNode* src : identifySources()){
for(const CallICFGNode* snk : identifySinks()){
vector<const ICFGNode*> path;
set<const ICFGNode*> visited;
std::stack<const SVFInstruction *>callstack;
if(aliasCheck(src,snk))
DFS(visited, path, callstack, src, snk);
reachability(src, snk);
}
}
}
Expand All @@ -88,10 +85,11 @@ void TaintGraphTraversal::taintChecking(){
/// bonus: dump and append each program path to a `ICFGPaths.txt` in the form of
/// ‘{ln: number cl: number, fl:name} -> {ln: number, cl: number, fl: name} -> {ln:number, cl: number, fl: name}
/// ln : line number cl: column number fl:file name for further learning, you can review the code in SVF, SVFUtil
void TaintGraphTraversal::printICFGPath(std::vector<const ICFGNode *> &path){
void TaintGraphTraversal::collectICFGPath(std::vector<unsigned> &path){

}


// TODO: Implement your code to parse the two lines from `SrcSnk.txt` in the form of
// line 1 for sources "{ api1 api2 api3 }"
// line 2 for sinks "{ api1 api2 api3 }"
Expand Down
2 changes: 1 addition & 1 deletion Assignment-4/Assignment-4.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TaintGraphTraversal : public ICFGTraversal{
std::set<const CallICFGNode *>& identifySinks();

// TODO: implement the path printing
void printICFGPath(std::vector<const ICFGNode *> &path);
void collectICFGPath(std::vector<unsigned> &path);

// TODO: Source and sink function names read from SrcSnk.txt
void readSrcSnkFromFile(const std::string& filename);
Expand Down
4 changes: 2 additions & 2 deletions Assignment-4/Test4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void Test1()
SVF::SVFIR *pag = builder.build();
TaintGraphTraversal* taint = new TaintGraphTraversal(pag);
taint->taintChecking();
set<string> expected = {"START: 5->1->2->3->6->7->8->9->END"};
set<string> expected = {"START->5->1->2->3->6->7->8->9->END"};
assert(taint->getPaths() == expected && " \n wrong paths generated - test1 failed !");
cout << "\n test1 passed !" << endl;
SVF::LLVMModuleSet::releaseLLVMModuleSet();
Expand Down Expand Up @@ -97,7 +97,7 @@ void Test4()
TaintGraphTraversal* taint = new TaintGraphTraversal(pag);

taint->taintChecking();
set<string> expected = {"START: 5->1->2->3->6->7->8->9->10->12->14->END"};
set<string> expected = {"START->5->1->2->3->6->7->8->9->10->12->14->END"};
assert(taint->getPaths() == expected && " \n wrong paths generated - test4 failed !");
cout << "\n test4 passed !" << endl;
SVF::LLVMModuleSet::releaseLLVMModuleSet();
Expand Down
Loading

0 comments on commit 94c05d9

Please sign in to comment.