Skip to content

Go: Fix "Parameter" in models-as-data #18565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Models-as-data models using "Parameter", "Parameter[n]" or "Parameter[n1..n2]" as the output now work correctly.
4 changes: 3 additions & 1 deletion go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ module SourceSinkInterpretationInput implements

/** Gets the callable that this node corresponds to, if any. */
DataFlowCallable asCallable() {
result.asSummarizedCallable().asFunction() = this.asElement().asEntity()
this.asElement().asEntity() = result.asSummarizedCallable().asFunction() or
this.asElement().asEntity() = result.asCallable().asFunction() or
this.asElement().asAstNode() = result.asCallable().asFuncLit()
}

/** Gets the target of this call, if any. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extensions:
data:
- ["github.com/nonexistent/test", "", False, "SourceVariable", "", "", "", "qltest", "manual"]
- ["github.com/nonexistent/test", "A", False, "Src1", "", "", "ReturnValue", "qltest", "manual"]
- ["semmle.go.Packages", "", True, "srcParam", "", "", "Parameter[0]", "qltest", "manual"]
- addsTo:
pack: codeql/go-all
extensible: sinkModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ invalidModelRow
| test.go:199:23:199:26 | arg2 | qltest |
| test.go:199:29:199:32 | arg3 | qltest |
| test.go:202:22:202:25 | temp | qltest |
| test.go:206:10:206:12 | src | qltest |
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ invalidModelRow
| test.go:187:24:187:31 | call to Src1 | qltest |
| test.go:191:24:191:31 | call to Src1 | qltest |
| test.go:201:10:201:28 | selection of SourceVariable | qltest |
| test.go:205:15:205:17 | definition of src | qltest |
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ extensions:
- ["github.com/nonexistent/test", "A", False, "SrcArg", "", "", "Argument[0]", "qltest-arg", "manual"]
- ["github.com/nonexistent/test", "A", False, "Src3", "", "", "ReturnValue[0]", "qltest", "manual"]
- ["github.com/nonexistent/test", "A", True, "Src3", "", "", "ReturnValue[1]", "qltest-w-subtypes", "manual"]
- ["semmle.go.Packages", "", True, "srcParam", "", "", "Parameter[0]", "qltest", "manual"]
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ func simpleflow() {
test.SinkVariable = temp // $ hasTaintFlow="temp"
}

func srcParam(src string, b test.B) {
b.Sink1(src) // $ hasTaintFlow="src"
}

type mapstringstringtype map[string]string
type arraytype []interface{}
type channeltype chan interface{}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extensions:
data:
- ["github.com/nonexistent/test", "", False, "SourceVariable", "", "", "", "qltest", "manual"]
- ["github.com/nonexistent/test", "A", False, "Src1", "", "", "ReturnValue", "qltest", "manual"]
- ["semmle.go.Packages", "", True, "srcParam", "", "", "Parameter[0]", "qltest", "manual"]
- addsTo:
pack: codeql/go-all
extensible: sinkModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ invalidModelRow
| test.go:206:10:206:26 | call to min | qltest |
| test.go:207:10:207:26 | call to min | qltest |
| test.go:210:22:210:25 | temp | qltest |
| test.go:214:10:214:12 | src | qltest |
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ invalidModelRow
| test.go:187:24:187:31 | call to Src1 | qltest |
| test.go:191:24:191:31 | call to Src1 | qltest |
| test.go:209:10:209:28 | selection of SourceVariable | qltest |
| test.go:213:15:213:17 | definition of src | qltest |
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ extensions:
- ["github.com/nonexistent/test", "A", False, "SrcArg", "", "", "Argument[0]", "qltest-arg", "manual"]
- ["github.com/nonexistent/test", "A", False, "Src3", "", "", "ReturnValue[0]", "qltest", "manual"]
- ["github.com/nonexistent/test", "A", True, "Src3", "", "", "ReturnValue[1]", "qltest-w-subtypes", "manual"]
- ["semmle.go.Packages", "", True, "srcParam", "", "", "Parameter[0]", "qltest", "manual"]
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func simpleflow() {
test.SinkVariable = temp // $ hasValueFlow="temp"
}

func srcParam(src string, b test.B) {
b.Sink1(src) // $ hasValueFlow="src"
}

type mapstringstringtype map[string]string
type arraytype []interface{}
type channeltype chan interface{}