Skip to content

Commit 12058a2

Browse files
committed
Fix containerStoreStep and containerReadStep
1 parent ab8096b commit 12058a2

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ predicate containerStoreStep(Node node1, Node node2, Content c) {
3434
)
3535
or
3636
c instanceof CollectionContent and
37-
exists(BinaryOperationNode send | send.hasOperands(node1, node2) | send.getOperator() = "<-")
37+
exists(SendStmt send |
38+
send.getChannel() = node2.(ExprNode).asExpr() and send.getValue() = node1.(ExprNode).asExpr()
39+
)
3840
or
3941
c instanceof MapKeyContent and
40-
node1.getType() instanceof MapType and
41-
exists(Write w | w.writesElement(node1, node2, _))
42+
node2.getType() instanceof MapType and
43+
exists(Write w | w.writesElement(node2, node1, _))
4244
or
4345
c instanceof MapValueContent and
44-
node1.getType() instanceof MapType and
45-
exists(Write w | w.writesElement(node1, _, node2))
46+
node2.getType() instanceof MapType and
47+
exists(Write w | w.writesElement(node2, _, node1))
4648
}
4749

4850
/**
@@ -65,7 +67,7 @@ predicate containerReadStep(Node node1, Node node2, Content c) {
6567
or
6668
c instanceof CollectionContent and
6769
exists(UnaryOperationNode recv | recv = node2 |
68-
node2 = recv.getOperand() and
70+
node1 = recv.getOperand() and
6971
recv.getOperator() = "<-"
7072
)
7173
or

ql/test/library-tests/semmle/go/dataflow/ExternalFlow/test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func simpleflow() {
9292

9393
taint10 := test.StepArgResCollectionContent(a.Src1()).(chan interface{})
9494
b.Sink1(test.GetElement(taint10)) // $ hasTaintFlow="call to GetElement"
95-
b.Sink1(<-taint10) // $ MISSING: hasTaintFlow="<-..."
95+
b.Sink1(<-taint10) // $ hasTaintFlow="<-..."
9696

9797
srcCollection := test.SetElement(a.Src1())
9898
taint11 := test.StepArgCollectionContentRes(srcCollection)
@@ -109,14 +109,14 @@ func simpleflow() {
109109

110110
srcMap13 := map[string]string{src.(string): ""}
111111
taint13 := test.StepArgMapKeyContentRes(srcMap13)
112-
b.Sink1(taint13) // $ MISSING: hasTaintFlow="taint13"
112+
b.Sink1(taint13) // $ hasTaintFlow="taint13"
113113

114114
taint14 := test.StepArgResMapValueContent(src).(map[string]string)
115115
b.Sink1(taint14[""]) // $ hasTaintFlow="index expression"
116116

117117
srcMap15 := map[string]string{"": src.(string)}
118118
taint15 := test.StepArgMapValueContentRes(srcMap15)
119-
b.Sink1(taint15) // $ MISSING: hasTaintFlow="taint15"
119+
b.Sink1(taint15) // $ hasTaintFlow="taint15"
120120

121121
slice := make([]interface{}, 0)
122122
slice = append(slice, src)

0 commit comments

Comments
 (0)