Skip to content

Commit b0bd610

Browse files
committed
update logic
1 parent dfa720c commit b0bd610

5 files changed

Lines changed: 46 additions & 33 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ gostd*.json
8181
init*.json
8282
callgraph.json
8383
passthrough.json
84+
additional.json
8485

8586
# BENCH FILE #
8687
######################

cmd/taintanalysis/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
func main() {
1010
// the ../../ takes you back to root of the project
1111
// and the ... means scan packages in package pkg recursively
12-
runner := taint.NewRunner(taint.Gostd...)
12+
runner := taint.NewRunner("../../pkg...")
1313
// the module name is the name defined in go.mod
1414
runner.ModuleName = "github.com/cokeBeer/goot"
15-
runner.PassThroughSrcPath = ""
15+
runner.PassThroughSrcPath = []string{}
1616
runner.PassThroughDstPath = "passthrough.json"
1717
runner.CallGraphDstPath = "callgraph.json"
18-
runner.PassThroughOnly = true
18+
runner.PassThroughOnly = false
1919
runner.InitOnly = false
2020
runner.Debug = true
21-
runner.PersistToNeo4j = true
21+
runner.PersistToNeo4j = false
2222
runner.Neo4jURI = "bolt://localhost:7687"
2323
runner.Neo4jUsername = "neo4j"
2424
runner.Neo4jPassword = "password"

pkg/example/dataflow/taint/persist.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,24 @@ func PersistToNeo4j(nodes *map[string]*Node, edges *map[string]*Edge, uri string
8686
}
8787

8888
// FetchPassThrough loads passthrougth data from target source
89-
func FetchPassThrough(passThroughContainer *map[string][][]int, src string) error {
90-
f, err := os.OpenFile(src, os.O_RDONLY|os.O_CREATE, 0666)
91-
if err != nil {
92-
return err
93-
}
94-
res, err := io.ReadAll(f)
95-
if err != nil {
96-
return err
97-
}
98-
err = json.Unmarshal(res, passThroughContainer)
99-
if err != nil {
100-
return err
89+
func FetchPassThrough(passThroughContainer *map[string][][]int, src []string) error {
90+
for _, path := range src {
91+
tmp := make(map[string][][]int)
92+
f, err := os.OpenFile(path, os.O_RDONLY|os.O_CREATE, 0666)
93+
if err != nil {
94+
return err
95+
}
96+
res, err := io.ReadAll(f)
97+
if err != nil {
98+
return err
99+
}
100+
err = json.Unmarshal(res, &tmp)
101+
if err != nil {
102+
return err
103+
}
104+
for k, v := range tmp {
105+
(*passThroughContainer)[k] = v
106+
}
101107
}
102108
return nil
103109
}

pkg/example/dataflow/taint/runner.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Runner struct {
1414
Debug bool
1515
InitOnly bool
1616
PassThroughOnly bool
17-
PassThroughSrcPath string
17+
PassThroughSrcPath []string
1818
PassThroughDstPath string
1919
CallGraphDstPath string
2020
Ruler rule.Ruler
@@ -27,7 +27,7 @@ type Runner struct {
2727
// NewRunner returns a *taint.Runner
2828
func NewRunner(PkgPath ...string) *Runner {
2929
return &Runner{PkgPath: PkgPath, ModuleName: "",
30-
PassThroughSrcPath: "", PassThroughDstPath: "",
30+
PassThroughSrcPath: nil, PassThroughDstPath: "",
3131
CallGraphDstPath: "", Ruler: nil,
3232
Debug: false, InitOnly: false, PassThroughOnly: false,
3333
PersistToNeo4j: false, Neo4jURI: "", Neo4jUsername: "", Neo4jPassword: ""}
@@ -65,10 +65,12 @@ func (r *Runner) Run() error {
6565
callGraph := NewCallGraph(&funcs, ruler)
6666

6767
passThroughContainter := make(map[string][][]int)
68-
if r.PassThroughSrcPath != "" {
68+
if r.PassThroughSrcPath != nil {
6969
FetchPassThrough(&passThroughContainter, r.PassThroughSrcPath)
7070
}
7171

72+
passThroughContainter["github.com/cokeBeer/goot/pkg/bench/copy.Copy"] = [][]int{{0}, {0, 1}}
73+
7274
initMap := make(map[string]*ssa.Function)
7375
history := make(map[string]bool)
7476

pkg/example/dataflow/taint/switcher.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,13 +1288,15 @@ func (s *TaintSwitcher) passStaticCallTaint(f *ssa.Function, inst *ssa.Call) {
12881288
}
12891289
} else {
12901290
// if the function has no receiver
1291-
if f.Signature.Results().Len() == 1 {
1292-
// if the function has one result
1293-
(*s.outMap)[inst.Name()] = newTaints[i]
1294-
} else if i < f.Signature.Results().Len() {
1295-
// else mark the variables as "inst.Name().X"
1296-
// e.g. t0.1, t0.2
1297-
(*s.outMap)[inst.Name()+"."+strconv.Itoa(i)] = newTaints[i]
1291+
if i < f.Signature.Results().Len() {
1292+
if f.Signature.Results().Len() == 1 {
1293+
// if the function has one result
1294+
(*s.outMap)[inst.Name()] = newTaints[i]
1295+
} else {
1296+
// else mark the variables as "inst.Name().X"
1297+
// e.g. t0.1, t0.2
1298+
(*s.outMap)[inst.Name()+"."+strconv.Itoa(i)] = newTaints[i]
1299+
}
12981300
} else {
12991301
// update args' taint
13001302
(*s.outMap)[inst.Call.Args[i-f.Signature.Results().Len()].Name()] = newTaints[i]
@@ -1519,13 +1521,15 @@ func (s *TaintSwitcher) passMethodTaint(f *ssa.Function, inst *ssa.Call) {
15191521
s.passPointTaint(newTaints[i], inst.Call.Value)
15201522
}
15211523
} else {
1522-
if f.Signature.Results().Len() == 1 {
1523-
// if the function has one result
1524-
(*s.outMap)[inst.Name()] = newTaints[i]
1525-
} else if i < 1+f.Signature.Results().Len() {
1526-
// else mark the variables as "inst.Name().X"
1527-
// e.g. t0.1, t0.2
1528-
(*s.outMap)[inst.Name()+"."+strconv.Itoa(i-1)] = newTaints[i]
1524+
if i < 1+f.Signature.Results().Len() {
1525+
if f.Signature.Results().Len() == 1 {
1526+
// if the function has one result
1527+
(*s.outMap)[inst.Name()] = newTaints[i]
1528+
} else {
1529+
// else mark the variables as "inst.Name().X"
1530+
// e.g. t0.1, t0.2
1531+
(*s.outMap)[inst.Name()+"."+strconv.Itoa(i-1)] = newTaints[i]
1532+
}
15291533
} else {
15301534
// update args' taint
15311535
(*s.outMap)[inst.Call.Args[i-f.Signature.Results().Len()-1].Name()] = newTaints[i]

0 commit comments

Comments
 (0)