forked from system-pclub/GCatch
/
special_instr.go
50 lines (42 loc) · 1.18 KB
/
special_instr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package mypointer
import (
"github.com/system-pclub/GCatch/GCatch/tools/go/ssa"
"strings"
)
// There are a few function calls we'd like to handle context sensitively
// 1. context APIs
// context APIs
var ctx_fn_list = []string{"context.WithValue","context.WithCancel","context.WithDeadline","context.WithTimeout"}
// some people still like to import from golang.org/
var ctx_fn_contain_list = []string{"golang.org/x/net/context.WithValue","golang.org/x/net/context.WithCancel","golang.org/x/net/context.WithDeadline","golang.org/x/net/context.WithTimeout"}
// 2. special functions
var special_fn_name_list = []string{"mygo"}
func is_in_sensitive_list(fn *ssa.Function) bool {
fn_str := fn.String()
fn_name := fn.Name()
if is_ctx_fn(fn_str) || is_special_fn_name(fn_name) {
return true
}
return false
}
func is_special_fn_name(name string) bool {
for _,sp_name := range special_fn_name_list {
if sp_name == name {
return true
}
}
return false
}
func is_ctx_fn(str string) bool {
for _,fn_str := range ctx_fn_list {
if str == fn_str {
return true
}
}
for _,fn_str := range ctx_fn_contain_list {
if strings.Contains(str,fn_str) {
return true
}
}
return false
}