Skip to content

Commit 06b9b76

Browse files
committed
Remove global function step from local flow
1 parent 97d8993 commit 06b9b76

File tree

4 files changed

+15
-54
lines changed

4 files changed

+15
-54
lines changed

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ predicate basicLocalFlowStep(Node nodeFrom, Node nodeTo) {
9595
nodeTo = instructionNode(succ) and
9696
nodeTo != nodeFrom
9797
)
98-
or
98+
}
99+
100+
overlay[global]
101+
predicate globalFunctionUseJumpStep(Node nodeFrom, Node nodeTo) {
99102
// GlobalFunctionNode -> use
100103
nodeFrom =
101104
any(GlobalFunctionNode fn | fn.getFunction() = nodeTo.asExpr().(FunctionName).getTarget())

go/ql/lib/semmle/go/frameworks/stdlib/IoFs.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@ module IoFs {
2121
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
2222
//signature: func WalkDir(fsys FS, root string, fn WalkDirFunc) error
2323
exists(DataFlow::CallNode call, DataFlow::FunctionNode f |
24-
call.getTarget().hasQualifiedName(packagePath(), "WalkDir") and
25-
f.getASuccessor*() = call.getArgument(2)
24+
f.(DataFlow::FuncLitNode).getASuccessor*() = call.getArgument(2)
25+
or
26+
exists(DataFlow::ExprNode functionName |
27+
f.(DataFlow::GlobalFunctionNode).getFunction() =
28+
functionName.asExpr().(FunctionName).getTarget()
29+
|
30+
functionName.getASuccessor*() = call.getArgument(2)
31+
)
2632
|
33+
call.getTarget().hasQualifiedName(packagePath(), "WalkDir") and
2734
pred = call.getArgument(0) and
2835
succ = f.getParameter([0, 1])
2936
)

go/ql/test/library-tests/semmle/go/dataflow/FlowSteps/LocalFlowStep.expected

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,3 @@
1-
| file://:0:0:0:0 | function Encode | url.go:51:14:51:21 | selection of Encode |
2-
| file://:0:0:0:0 | function EscapedPath | url.go:28:14:28:26 | selection of EscapedPath |
3-
| file://:0:0:0:0 | function Get | url.go:52:14:52:18 | selection of Get |
4-
| file://:0:0:0:0 | function Hostname | url.go:29:14:29:23 | selection of Hostname |
5-
| file://:0:0:0:0 | function JoinPath | url.go:57:16:57:27 | selection of JoinPath |
6-
| file://:0:0:0:0 | function JoinPath | url.go:58:16:58:27 | selection of JoinPath |
7-
| file://:0:0:0:0 | function JoinPath | url.go:60:15:60:28 | selection of JoinPath |
8-
| file://:0:0:0:0 | function JoinPath | url.go:66:9:66:25 | selection of JoinPath |
9-
| file://:0:0:0:0 | function MarshalBinary | url.go:30:11:30:25 | selection of MarshalBinary |
10-
| file://:0:0:0:0 | function Parse | url.go:23:10:23:18 | selection of Parse |
11-
| file://:0:0:0:0 | function Parse | url.go:32:9:32:15 | selection of Parse |
12-
| file://:0:0:0:0 | function Parse | url.go:59:14:59:22 | selection of Parse |
13-
| file://:0:0:0:0 | function Parse | url.go:65:17:65:25 | selection of Parse |
14-
| file://:0:0:0:0 | function ParseQuery | url.go:50:10:50:23 | selection of ParseQuery |
15-
| file://:0:0:0:0 | function ParseRequestURI | url.go:27:9:27:27 | selection of ParseRequestURI |
16-
| file://:0:0:0:0 | function Password | url.go:43:11:43:21 | selection of Password |
17-
| file://:0:0:0:0 | function PathEscape | url.go:12:31:12:44 | selection of PathEscape |
18-
| file://:0:0:0:0 | function PathUnescape | url.go:12:14:12:29 | selection of PathUnescape |
19-
| file://:0:0:0:0 | function Port | url.go:33:14:33:19 | selection of Port |
20-
| file://:0:0:0:0 | function Println | url.go:28:2:28:12 | selection of Println |
21-
| file://:0:0:0:0 | function Println | url.go:29:2:29:12 | selection of Println |
22-
| file://:0:0:0:0 | function Println | url.go:31:2:31:12 | selection of Println |
23-
| file://:0:0:0:0 | function Println | url.go:33:2:33:12 | selection of Println |
24-
| file://:0:0:0:0 | function Println | url.go:34:2:34:12 | selection of Println |
25-
| file://:0:0:0:0 | function Println | url.go:35:2:35:12 | selection of Println |
26-
| file://:0:0:0:0 | function Println | url.go:44:2:44:12 | selection of Println |
27-
| file://:0:0:0:0 | function Println | url.go:45:2:45:12 | selection of Println |
28-
| file://:0:0:0:0 | function Println | url.go:51:2:51:12 | selection of Println |
29-
| file://:0:0:0:0 | function Println | url.go:52:2:52:12 | selection of Println |
30-
| file://:0:0:0:0 | function Query | url.go:34:14:34:20 | selection of Query |
31-
| file://:0:0:0:0 | function QueryEscape | url.go:14:32:14:46 | selection of QueryEscape |
32-
| file://:0:0:0:0 | function QueryUnescape | url.go:14:14:14:30 | selection of QueryUnescape |
33-
| file://:0:0:0:0 | function Replace | strings.go:9:8:9:22 | selection of Replace |
34-
| file://:0:0:0:0 | function ReplaceAll | strings.go:10:8:10:25 | selection of ReplaceAll |
35-
| file://:0:0:0:0 | function RequestURI | url.go:35:14:35:25 | selection of RequestURI |
36-
| file://:0:0:0:0 | function ResolveReference | url.go:36:6:36:23 | selection of ResolveReference |
37-
| file://:0:0:0:0 | function Sprint | strings.go:11:9:11:18 | selection of Sprint |
38-
| file://:0:0:0:0 | function Sprintf | strings.go:11:30:11:40 | selection of Sprintf |
39-
| file://:0:0:0:0 | function Sprintln | strings.go:11:54:11:65 | selection of Sprintln |
40-
| file://:0:0:0:0 | function User | url.go:41:8:41:15 | selection of User |
41-
| file://:0:0:0:0 | function UserPassword | url.go:42:7:42:22 | selection of UserPassword |
42-
| file://:0:0:0:0 | function Username | url.go:45:14:45:24 | selection of Username |
43-
| file://:0:0:0:0 | function append | main.go:39:8:39:13 | append |
44-
| file://:0:0:0:0 | function append | main.go:40:8:40:13 | append |
45-
| file://:0:0:0:0 | function copy | main.go:42:2:42:5 | copy |
46-
| file://:0:0:0:0 | function make | main.go:41:8:41:11 | make |
47-
| file://:0:0:0:0 | function max | main.go:65:7:65:9 | max |
48-
| file://:0:0:0:0 | function min | main.go:64:7:64:9 | min |
49-
| main.go:3:6:3:10 | function test1 | main.go:34:2:34:6 | test1 |
501
| main.go:3:12:3:12 | argument corresponding to x | main.go:3:12:3:12 | definition of x |
512
| main.go:3:12:3:12 | definition of x | main.go:5:5:5:5 | x |
523
| main.go:3:19:3:20 | argument corresponding to fn | main.go:3:19:3:20 | definition of fn |
@@ -66,8 +17,6 @@
6617
| main.go:10:12:10:12 | y | main.go:10:17:10:17 | y |
6718
| main.go:10:17:10:27 | ...>=... | main.go:10:7:10:27 | ...&&... |
6819
| main.go:11:14:11:14 | z | main.go:11:9:11:15 | type conversion |
69-
| main.go:14:6:14:10 | function test2 | main.go:34:8:34:12 | test2 |
70-
| main.go:14:6:14:10 | function test2 | main.go:34:19:34:23 | test2 |
7120
| main.go:15:9:15:9 | 0 | main.go:15:2:15:4 | definition of acc |
7221
| main.go:16:9:19:2 | capture variable acc | main.go:17:3:17:5 | acc |
7322
| main.go:17:3:17:7 | definition of acc | main.go:18:10:18:12 | acc |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| IoFs.go:95:13:95:25 | call to newSource | No flow to its sink |
2+
| IoFs.go:99:13:99:25 | call to newSource | No flow to its sink |

0 commit comments

Comments
 (0)