mirror of
https://github.com/github/codeql.git
synced 2026-01-30 06:42:57 +01:00
Add tests for data and taint flow through arrays and var args
This commit is contained in:
56
ql/test/library-tests/semmle/go/dataflow/VarArgs/Flows.ql
Normal file
56
ql/test/library-tests/semmle/go/dataflow/VarArgs/Flows.ql
Normal file
@@ -0,0 +1,56 @@
|
||||
import go
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
|
||||
class DataConfiguration extends DataFlow::Configuration {
|
||||
DataConfiguration() { this = "data-configuration" }
|
||||
|
||||
override predicate isSource(DataFlow::Node source) {
|
||||
source = any(DataFlow::CallNode c | c.getCalleeName() = "source").getResult(0)
|
||||
}
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) {
|
||||
sink = any(DataFlow::CallNode c | c.getCalleeName() = "sink").getArgument(0)
|
||||
}
|
||||
}
|
||||
|
||||
class DataFlowTest extends InlineExpectationsTest {
|
||||
DataFlowTest() { this = "DataFlowTest" }
|
||||
|
||||
override string getARelevantTag() { result = "dataflow" }
|
||||
|
||||
override predicate hasActualResult(string file, int line, string element, string tag, string value) {
|
||||
tag = "dataflow" and
|
||||
exists(DataFlow::Node sink | any(DataConfiguration c).hasFlow(_, sink) |
|
||||
element = sink.toString() and
|
||||
value = "" and
|
||||
sink.hasLocationInfo(file, line, _, _, _)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class TaintConfiguration extends TaintTracking::Configuration {
|
||||
TaintConfiguration() { this = "taint-configuration" }
|
||||
|
||||
override predicate isSource(DataFlow::Node source) {
|
||||
source = any(DataFlow::CallNode c | c.getCalleeName() = "source").getResult(0)
|
||||
}
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) {
|
||||
sink = any(DataFlow::CallNode c | c.getCalleeName() = "sink").getArgument(0)
|
||||
}
|
||||
}
|
||||
|
||||
class TaintFlowTest extends InlineExpectationsTest {
|
||||
TaintFlowTest() { this = "TaintFlowTest" }
|
||||
|
||||
override string getARelevantTag() { result = "taintflow" }
|
||||
|
||||
override predicate hasActualResult(string file, int line, string element, string tag, string value) {
|
||||
tag = "taintflow" and
|
||||
exists(DataFlow::Node sink | any(TaintConfiguration c).hasFlow(_, sink) |
|
||||
element = sink.toString() and
|
||||
value = "" and
|
||||
sink.hasLocationInfo(file, line, _, _, _)
|
||||
)
|
||||
}
|
||||
}
|
||||
27
ql/test/library-tests/semmle/go/dataflow/VarArgs/main.go
Normal file
27
ql/test/library-tests/semmle/go/dataflow/VarArgs/main.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
func source() string {
|
||||
return "untrusted data"
|
||||
}
|
||||
|
||||
func sink(string) {
|
||||
}
|
||||
|
||||
type A struct {
|
||||
f string
|
||||
}
|
||||
|
||||
func functionWithVarArgsOfStructsParameter(s ...A) {
|
||||
sink(s[0].f) // $ MISSING: taintflow dataflow
|
||||
}
|
||||
|
||||
func main() {
|
||||
stringSlice := []string{source()}
|
||||
sink(stringSlice[0]) // $ taintflow MISSING: dataflow
|
||||
|
||||
arrayOfStructs := []A{{f: source()}}
|
||||
sink(arrayOfStructs[0].f) // $ MISSING: taintflow dataflow
|
||||
|
||||
a := A{f: source()}
|
||||
functionWithVarArgsOfStructsParameter(a)
|
||||
}
|
||||
Reference in New Issue
Block a user