Skip to content

Commit a357712

Browse files
committed
Make separate post-update nodes
1 parent 57fbd53 commit a357712

File tree

4 files changed

+59
-46
lines changed

4 files changed

+59
-46
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ private newtype TNode =
1212
MkGlobalFunctionNode(Function f) or
1313
MkImplicitVarargsSlice(CallExpr c) { c.hasImplicitVarargs() } or
1414
MkSliceElementNode(SliceExpr se) or
15-
MkFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn)
15+
MkFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn) or
16+
MkDefaultPostUpdateNode(IR::Instruction insn) { insnHasPostUpdateNode(insn) }
1617

1718
/** Nodes intended for only use inside the data-flow libraries. */
1819
module Private {
@@ -844,20 +845,22 @@ module Public {
844845
insn = getAWrittenInsn()
845846
}
846847

847-
private class DefaultPostUpdateNode extends PostUpdateNode {
848+
private class DefaultPostUpdateNode extends PostUpdateNode, MkDefaultPostUpdateNode {
848849
Node preupd;
849850

850-
DefaultPostUpdateNode() {
851-
insnHasPostUpdateNode(preupd.asInstruction()) and
852-
(
853-
preupd = this.(SsaNode).getAUse()
854-
or
855-
preupd = this and
856-
not basicLocalFlowStep(_, this)
857-
)
858-
}
851+
DefaultPostUpdateNode() { this = MkDefaultPostUpdateNode(preupd.asInstruction()) }
859852

860853
override Node getPreUpdateNode() { result = preupd }
854+
855+
override ControlFlow::Root getRoot() { result = preupd.getRoot() }
856+
857+
override Type getType() { result = preupd.getType() }
858+
859+
override string getNodeKind() { result = "post-update node" }
860+
861+
override string toString() { result = preupd.toString() + " [postupdate]" }
862+
863+
override Location getLocation() { result = preupd.getLocation() }
861864
}
862865

863866
/**

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ predicate basicLocalFlowStep(Node nodeFrom, Node nodeTo) {
6868
// Instruction -> SSA defn
6969
exists(IR::Instruction pred, SsaExplicitDefinition succ |
7070
succ.getRhs() = pred and
71-
nodeFrom = instructionNode(pred) and
71+
(
72+
nodeFrom = instructionNode(pred) or
73+
nodeFrom.(PostUpdateNode).getPreUpdateNode() = instructionNode(pred)
74+
) and
7275
nodeTo = ssaNode(succ.getVariable())
7376
)
7477
or
@@ -82,7 +85,10 @@ predicate basicLocalFlowStep(Node nodeFrom, Node nodeTo) {
8285
// SSA use -> successive SSA use
8386
// Note this case includes Phi node traversal
8487
exists(IR::Instruction pred, IR::Instruction succ | succ = getAnAdjacentUse(pred) |
85-
nodeFrom = instructionNode(pred) and
88+
(
89+
nodeFrom = instructionNode(pred) or
90+
nodeFrom.(PostUpdateNode).getPreUpdateNode() = instructionNode(pred)
91+
) and
8692
nodeTo = instructionNode(succ)
8793
)
8894
or

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,18 @@ class AdditionalTaintStep extends Unit {
8888
* global taint flow configurations.
8989
*/
9090
predicate localAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ, string model) {
91-
(
92-
referenceStep(pred, succ) or
93-
elementWriteStep(pred, succ) or
94-
fieldReadStep(pred, succ) or
95-
elementStep(pred, succ) or
96-
tupleStep(pred, succ) or
97-
stringConcatStep(pred, succ) or
98-
sliceStep(pred, succ)
91+
exists(DataFlow::Node pred2 |
92+
pred2 = pred
93+
or
94+
pred2 = pred.(DataFlow::PostUpdateNode).getPreUpdateNode()
95+
|
96+
referenceStep(pred2, succ) or
97+
elementWriteStep(pred2, succ) or
98+
fieldReadStep(pred2, succ) or
99+
elementStep(pred2, succ) or
100+
tupleStep(pred2, succ) or
101+
stringConcatStep(pred2, succ) or
102+
sliceStep(pred2, succ)
99103
) and
100104
model = ""
101105
or
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
| file://:0:0:0:0 | [summary param] 0 in copy | file://:0:0:0:0 | [summary] to write: Argument[0] in copy |
2-
| test.go:23:2:23:2 | a | test.go:22:2:22:2 | definition of a |
3-
| test.go:23:11:23:14 | &... | test.go:23:11:23:14 | &... |
4-
| test.go:23:12:23:14 | selection of b | test.go:23:12:23:14 | selection of b |
5-
| test.go:24:2:24:2 | a | test.go:22:2:22:2 | definition of a |
6-
| test.go:24:2:24:5 | selection of bs | test.go:24:2:24:5 | selection of bs |
7-
| test.go:24:2:24:8 | index expression | test.go:24:2:24:8 | index expression |
8-
| test.go:24:17:24:20 | &... | test.go:24:17:24:20 | &... |
9-
| test.go:24:18:24:20 | struct literal | test.go:24:18:24:20 | struct literal |
10-
| test.go:25:2:25:2 | a | test.go:22:2:22:2 | definition of a |
11-
| test.go:25:2:25:5 | selection of bs | test.go:25:2:25:5 | selection of bs |
12-
| test.go:25:2:25:8 | index expression | test.go:25:2:25:8 | index expression |
13-
| test.go:25:2:25:13 | implicit dereference | test.go:25:2:25:13 | implicit dereference |
14-
| test.go:25:2:25:13 | selection of cptr | test.go:25:2:25:13 | selection of cptr |
15-
| test.go:26:2:26:2 | a | test.go:22:2:22:2 | definition of a |
16-
| test.go:26:2:26:7 | implicit dereference | test.go:26:2:26:7 | implicit dereference |
17-
| test.go:26:2:26:7 | selection of bptr | test.go:26:2:26:7 | selection of bptr |
18-
| test.go:26:2:26:12 | implicit dereference | test.go:26:2:26:12 | implicit dereference |
19-
| test.go:26:2:26:12 | selection of cptr | test.go:26:2:26:12 | selection of cptr |
20-
| test.go:28:7:28:10 | struct literal | test.go:28:7:28:10 | struct literal |
21-
| test.go:29:2:29:2 | c | test.go:28:2:28:2 | definition of c |
22-
| test.go:29:6:29:6 | a | test.go:22:2:22:2 | definition of a |
23-
| test.go:30:2:30:2 | c | test.go:28:2:28:2 | definition of c |
24-
| test.go:30:7:30:7 | a | test.go:22:2:22:2 | definition of a |
25-
| test.go:35:4:35:4 | a | test.go:22:2:22:2 | definition of a |
26-
| test.go:36:5:36:5 | a | test.go:22:2:22:2 | definition of a |
2+
| test.go:23:2:23:2 | a | test.go:23:2:23:2 | a [postupdate] |
3+
| test.go:23:11:23:14 | &... | test.go:23:11:23:14 | &... [postupdate] |
4+
| test.go:23:12:23:14 | selection of b | test.go:23:12:23:14 | selection of b [postupdate] |
5+
| test.go:24:2:24:2 | a | test.go:24:2:24:2 | a [postupdate] |
6+
| test.go:24:2:24:5 | selection of bs | test.go:24:2:24:5 | selection of bs [postupdate] |
7+
| test.go:24:2:24:8 | index expression | test.go:24:2:24:8 | index expression [postupdate] |
8+
| test.go:24:17:24:20 | &... | test.go:24:17:24:20 | &... [postupdate] |
9+
| test.go:24:18:24:20 | struct literal | test.go:24:18:24:20 | struct literal [postupdate] |
10+
| test.go:25:2:25:2 | a | test.go:25:2:25:2 | a [postupdate] |
11+
| test.go:25:2:25:5 | selection of bs | test.go:25:2:25:5 | selection of bs [postupdate] |
12+
| test.go:25:2:25:8 | index expression | test.go:25:2:25:8 | index expression [postupdate] |
13+
| test.go:25:2:25:13 | implicit dereference | test.go:25:2:25:13 | implicit dereference [postupdate] |
14+
| test.go:25:2:25:13 | selection of cptr | test.go:25:2:25:13 | selection of cptr [postupdate] |
15+
| test.go:26:2:26:2 | a | test.go:26:2:26:2 | a [postupdate] |
16+
| test.go:26:2:26:7 | implicit dereference | test.go:26:2:26:7 | implicit dereference [postupdate] |
17+
| test.go:26:2:26:7 | selection of bptr | test.go:26:2:26:7 | selection of bptr [postupdate] |
18+
| test.go:26:2:26:12 | implicit dereference | test.go:26:2:26:12 | implicit dereference [postupdate] |
19+
| test.go:26:2:26:12 | selection of cptr | test.go:26:2:26:12 | selection of cptr [postupdate] |
20+
| test.go:28:7:28:10 | struct literal | test.go:28:7:28:10 | struct literal [postupdate] |
21+
| test.go:29:2:29:2 | c | test.go:29:2:29:2 | c [postupdate] |
22+
| test.go:29:6:29:6 | a | test.go:29:6:29:6 | a [postupdate] |
23+
| test.go:30:2:30:2 | c | test.go:30:2:30:2 | c [postupdate] |
24+
| test.go:30:7:30:7 | a | test.go:30:7:30:7 | a [postupdate] |
25+
| test.go:35:4:35:4 | a | test.go:35:4:35:4 | a [postupdate] |
26+
| test.go:36:5:36:5 | a | test.go:36:5:36:5 | a [postupdate] |

0 commit comments

Comments
 (0)