Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 4b56581

Browse files
author
Max Schaefer
committed
Fix input nodes for results that are not assigned to an SSA variable.
1 parent 9c640ff commit 4b56581

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,20 @@ private class ResultInput extends FunctionInput, TInResult {
107107
}
108108

109109
override DataFlow::Node getEntryNode(DataFlow::CallNode c) {
110-
exists(DataFlow::PostUpdateNode pun, DataFlow::Node init |
111-
pun = result and
112-
init = pun.(DataFlow::SsaNode).getInit()
113-
|
110+
exists(DataFlow::Node pred |
114111
index = -1 and
115-
init = c.getResult()
112+
pred = c.getResult()
116113
or
117114
index >= 0 and
118-
init = c.getResult(index)
115+
pred = c.getResult(index)
116+
|
117+
// if the result is assigned to an SSA variable, we want to propagate mutations backwards
118+
// through that variable
119+
exists(DataFlow::SsaNode ssa | ssa.getInit() = pred | result = ssa.(DataFlow::PostUpdateNode))
120+
or
121+
// otherwise the entry node is simply the result
122+
not exists(DataFlow::SsaNode ssa | ssa.getInit() = pred) and
123+
result = pred
119124
)
120125
}
121126

ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionInput_getEntryNode.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,13 @@
2121
| receiver | reset.go:12:2:12:21 | call to Reset | reset.go:12:2:12:7 | reader |
2222
| receiver | tst2.go:10:9:10:39 | call to Encode | tst2.go:10:9:10:26 | call to NewEncoder |
2323
| receiver | tst.go:10:2:10:29 | call to ReadFrom | tst.go:10:2:10:12 | bytesBuffer |
24+
| result | main.go:51:2:51:14 | call to op | main.go:51:2:51:14 | call to op |
25+
| result | main.go:53:2:53:22 | call to op2 | main.go:53:2:53:22 | call to op2 |
26+
| result | main.go:53:14:53:21 | call to bump | main.go:53:14:53:21 | call to bump |
27+
| result | tst2.go:10:9:10:26 | call to NewEncoder | tst2.go:10:9:10:26 | call to NewEncoder |
2428
| result | tst.go:9:17:9:33 | call to new | tst.go:9:2:9:12 | definition of bytesBuffer |
29+
| result 0 | main.go:51:2:51:14 | call to op | main.go:51:2:51:14 | call to op |
30+
| result 0 | main.go:53:2:53:22 | call to op2 | main.go:53:2:53:22 | call to op2 |
31+
| result 0 | main.go:53:14:53:21 | call to bump | main.go:53:14:53:21 | call to bump |
32+
| result 0 | tst2.go:10:9:10:26 | call to NewEncoder | tst2.go:10:9:10:26 | call to NewEncoder |
2533
| result 0 | tst.go:9:17:9:33 | call to new | tst.go:9:2:9:12 | definition of bytesBuffer |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| file://:0:0:0:0 | Encode | tst2.go:10:35:10:38 | data | tst2.go:10:9:10:26 | call to NewEncoder |
2+
| file://:0:0:0:0 | NewEncoder | tst2.go:10:9:10:26 | call to NewEncoder | tst2.go:9:6:9:6 | definition of w |
23
| file://:0:0:0:0 | ReadFrom | tst.go:10:23:10:28 | reader | tst.go:9:2:9:12 | definition of bytesBuffer |
34
| file://:0:0:0:0 | Reset | reset.go:12:15:12:20 | source | reset.go:11:6:11:11 | definition of reader |

0 commit comments

Comments
 (0)