-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18235 from owen-mc/go/varargs-out-param
Go: Improve data flow out of variadic parameter
- Loading branch information
Showing
26 changed files
with
350 additions
and
9 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
go/ql/lib/change-notes/2024-12-06-improve-flow-out-of-variadic-parameter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* Data flow out of variadic parameters now works in more situations. Summary models defined using models-as-data work. Source models defined using models-as-data do not work yet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/Flows.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
testFailures | ||
invalidModelRow |
21 changes: 21 additions & 0 deletions
21
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/Flows.ext.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extensions: | ||
- addsTo: | ||
pack: codeql/go-all | ||
extensible: summaryModel | ||
data: | ||
- ["github.com/nonexistent/test", "", False, "FunctionWithParameter", "", "", "Argument[0]", "ReturnValue", "value", "manual"] | ||
- ["github.com/nonexistent/test", "", False, "FunctionWithSliceParameter", "", "", "Argument[0].ArrayElement", "ReturnValue", "value", "manual"] | ||
- ["github.com/nonexistent/test", "", False, "FunctionWithVarArgsParameter", "", "", "Argument[0].ArrayElement", "ReturnValue", "value", "manual"] | ||
- ["github.com/nonexistent/test", "", False, "FunctionWithVarArgsOutParameter", "", "", "Argument[0]", "Argument[1].ArrayElement", "value", "manual"] | ||
- ["github.com/nonexistent/test", "", False, "FunctionWithSliceOfStructsParameter", "", "", "Argument[0].ArrayElement.Field[github.com/nonexistent/test.A.Field]", "ReturnValue", "value", "manual"] | ||
- ["github.com/nonexistent/test", "", False, "FunctionWithVarArgsOfStructsParameter", "", "", "Argument[0].ArrayElement.Field[github.com/nonexistent/test.A.Field]", "ReturnValue", "value", "manual"] | ||
- addsTo: | ||
pack: codeql/go-all | ||
extensible: sourceModel | ||
data: | ||
- ["github.com/nonexistent/test", "", False, "VariadicSource", "", "", "Argument[0]", "qltest", "manual"] | ||
- addsTo: | ||
pack: codeql/go-all | ||
extensible: sinkModel | ||
data: | ||
- ["github.com/nonexistent/test", "", False, "VariadicSink", "", "", "Argument[0]", "qltest", "manual"] |
22 changes: 22 additions & 0 deletions
22
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/Flows.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import go | ||
import semmle.go.dataflow.ExternalFlow | ||
import ModelValidation | ||
import TestUtilities.InlineFlowTest | ||
|
||
module Config implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node source) { | ||
sourceNode(source, "qltest") | ||
or | ||
exists(Function fn | fn.hasQualifiedName(_, ["source", "taint"]) | | ||
source = fn.getACall().getResult() | ||
) | ||
} | ||
|
||
predicate isSink(DataFlow::Node sink) { | ||
sinkNode(sink, "qltest") | ||
or | ||
exists(Function fn | fn.hasQualifiedName(_, "sink") | sink = fn.getACall().getAnArgument()) | ||
} | ||
} | ||
|
||
import FlowTest<Config, Config> |
5 changes: 5 additions & 0 deletions
5
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/go.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module semmle.go.Packages | ||
|
||
go 1.23 | ||
|
||
require github.com/nonexistent/test v0.0.0-20200203000000-0000000000000 |
51 changes: 51 additions & 0 deletions
51
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/nonexistent/test" | ||
) | ||
|
||
func source() string { | ||
return "untrusted data" | ||
} | ||
|
||
func sink(any) { | ||
} | ||
|
||
func main() { | ||
s := source() | ||
sink(test.FunctionWithParameter(s)) // $ hasValueFlow="call to FunctionWithParameter" | ||
|
||
stringSlice := []string{source()} | ||
sink(stringSlice[0]) // $ hasValueFlow="index expression" | ||
|
||
s0 := "" | ||
s1 := source() | ||
sSlice := []string{s0, s1} | ||
sink(test.FunctionWithParameter(sSlice[1])) // $ hasValueFlow="call to FunctionWithParameter" | ||
sink(test.FunctionWithSliceParameter(sSlice)) // $ hasValueFlow="call to FunctionWithSliceParameter" | ||
sink(test.FunctionWithVarArgsParameter(sSlice...)) // $ hasValueFlow="call to FunctionWithVarArgsParameter" | ||
sink(test.FunctionWithVarArgsParameter(s0, s1)) // $ hasValueFlow="call to FunctionWithVarArgsParameter" | ||
|
||
var out1 *string | ||
var out2 *string | ||
test.FunctionWithVarArgsOutParameter(source(), out1, out2) | ||
sink(out1) // $ hasValueFlow="out1" | ||
sink(out2) // $ hasValueFlow="out2" | ||
|
||
sliceOfStructs := []test.A{{Field: source()}} | ||
sink(sliceOfStructs[0].Field) // $ hasValueFlow="selection of Field" | ||
|
||
a0 := test.A{Field: ""} | ||
a1 := test.A{Field: source()} | ||
aSlice := []test.A{a0, a1} | ||
sink(test.FunctionWithSliceOfStructsParameter(aSlice)) // $ hasValueFlow="call to FunctionWithSliceOfStructsParameter" | ||
sink(test.FunctionWithVarArgsOfStructsParameter(aSlice...)) // $ hasValueFlow="call to FunctionWithVarArgsOfStructsParameter" | ||
sink(test.FunctionWithVarArgsOfStructsParameter(a0, a1)) // $ hasValueFlow="call to FunctionWithVarArgsOfStructsParameter" | ||
|
||
var variadicSource string | ||
test.VariadicSource(&variadicSource) | ||
sink(variadicSource) // $ MISSING: hasTaintFlow="variadicSource" | ||
|
||
test.VariadicSink(source()) // $ hasTaintFlow="[]type{args}" | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...sts/semmle/go/dataflow/VarArgsWithExternalFlow/vendor/github.com/nonexistent/test/stub.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/vendor/modules.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# github.com/nonexistent/test v0.0.0-20200203000000-0000000000000 | ||
## explicit | ||
github.com/nonexistent/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithFunctionModels/go.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module semmle.go.Packages | ||
|
||
go 1.17 | ||
go 1.23 | ||
|
||
require github.com/nonexistent/test v0.0.0-20200203000000-0000000000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-1.09 MB
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithFunctionModels/semmle.go.Packages
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
...s/semmle/go/dataflow/VarArgsWithFunctionModels/vendor/github.com/nonexistent/test/stub.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.