File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed
go/analysis/passes/sigchanyzer Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ func run(pass *analysis.Pass) (interface{}, error) {
49
49
chanDecl = decl
50
50
}
51
51
case * ast.CallExpr :
52
+ // Only signal.Notify(make(chan os.Signal), os.Interrupt) is safe,
53
+ // conservatively treate others as not safe, see golang/go#45043
54
+ if isBuiltinMake (pass .TypesInfo , arg ) {
55
+ return
56
+ }
52
57
chanDecl = arg
53
58
}
54
59
if chanDecl == nil || len (chanDecl .Args ) != 1 {
@@ -127,3 +132,16 @@ func findDecl(arg *ast.Ident) ast.Node {
127
132
}
128
133
return nil
129
134
}
135
+
136
+ func isBuiltinMake (info * types.Info , call * ast.CallExpr ) bool {
137
+ typVal := info .Types [call .Fun ]
138
+ if ! typVal .IsBuiltin () {
139
+ return false
140
+ }
141
+ switch fun := call .Fun .(type ) {
142
+ case * ast.Ident :
143
+ return info .ObjectOf (fun ).Name () == "make"
144
+ default :
145
+ return false
146
+ }
147
+ }
Original file line number Diff line number Diff line change @@ -36,3 +36,19 @@ func j() {
36
36
f := signal .Notify
37
37
f (c , os .Interrupt ) // want "misuse of unbuffered os.Signal channel as argument to signal.Notify"
38
38
}
39
+
40
+ func k () {
41
+ signal .Notify (make (chan os.Signal ), os .Interrupt ) // ok
42
+ }
43
+
44
+ func l () {
45
+ signal .Notify (make (chan os.Signal , 1 ), os .Interrupt ) // ok
46
+ }
47
+
48
+ func m () {
49
+ signal .Notify (make (chan ao.Signal , 1 ), os .Interrupt ) // ok
50
+ }
51
+
52
+ func n () {
53
+ signal .Notify (make (chan ao.Signal ), os .Interrupt ) // ok
54
+ }
Original file line number Diff line number Diff line change @@ -36,3 +36,19 @@ func j() {
36
36
f := signal.Notify
37
37
f(c, os.Interrupt) // want "misuse of unbuffered os.Signal channel as argument to signal.Notify"
38
38
}
39
+
40
+ func k() {
41
+ signal.Notify(make(chan os.Signal), os.Interrupt) // ok
42
+ }
43
+
44
+ func l() {
45
+ signal.Notify(make(chan os.Signal, 1), os.Interrupt) // ok
46
+ }
47
+
48
+ func m() {
49
+ signal.Notify(make(chan ao.Signal, 1), os.Interrupt) // ok
50
+ }
51
+
52
+ func n() {
53
+ signal.Notify(make(chan ao.Signal), os.Interrupt) // ok
54
+ }
You can’t perform that action at this time.
0 commit comments