Skip to content

Commit 6757271

Browse files
committed
Fix flow out of varargs param with models-as-data
This still doesn't allow for a variadic out parameter to be defined as a source using MaD. This is due to the lack of an implicit store step at sources, to match implicit read steps at sinks.
1 parent 8cc4cd5 commit 6757271

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ predicate containerReadStep(Node node1, Node node2, Content c) {
6666
(
6767
node2.(Read).readsElement(node1, _)
6868
or
69+
exists(ImplicitVarargsSlice ivs |
70+
node1.(PostUpdateNode).getPreUpdateNode() = ivs and
71+
node2.(PostUpdateNode).getPreUpdateNode() = ivs.getCallNode().getAnImplicitVarargsArgument()
72+
)
73+
or
6974
node2.(RangeElementNode).getBase() = node1
7075
or
7176
// To model data flow from array elements of the base of a `SliceNode` to

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,9 @@ module Public {
845845
or
846846
preupd = getAWrittenNode()
847847
or
848+
preupd instanceof ImplicitVarargsSlice and
849+
mutableType(preupd.(ImplicitVarargsSlice).getType().(SliceType).getElementType())
850+
or
848851
preupd = any(ArgumentNode arg).getACorrespondingSyntacticArgument() and
849852
mutableType(preupd.getType())
850853
) and

go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func main() {
2929
var out1 *string
3030
var out2 *string
3131
test.FunctionWithVarArgsOutParameter(source(), out1, out2)
32-
sink(out1) // $ MISSING: hasValueFlow="out1"
33-
sink(out2) // $ MISSING: hasValueFlow="out2"
32+
sink(out1) // $ hasValueFlow="out1"
33+
sink(out2) // $ hasValueFlow="out2"
3434

3535
sliceOfStructs := []test.A{{Field: source()}}
3636
sink(sliceOfStructs[0].Field) // $ hasValueFlow="selection of Field"

0 commit comments

Comments
 (0)