-
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 #15613 from smowton/smowton/fix/golang-map-range-r…
…ead-dataflow Golang: fix flow from a map value via a range statement
- Loading branch information
Showing
5 changed files
with
40 additions
and
8 deletions.
There are no files selected for viewing
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: fix | ||
--- | ||
* Fixed dataflow out of a `map` using a `range` statement. |
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
Empty file.
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/dataflow/MapReadsAndStores/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,3 @@ | ||
import go | ||
import TestUtilities.InlineFlowTest | ||
import DefaultFlowTest |
25 changes: 25 additions & 0 deletions
25
go/ql/test/library-tests/semmle/go/dataflow/MapReadsAndStores/test.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,25 @@ | ||
package main | ||
|
||
func source() string { | ||
return "untrusted data" | ||
} | ||
|
||
func sink(any) { | ||
} | ||
|
||
func main() { | ||
var someMap map[string]string = map[string]string{} | ||
someMap["someKey"] = source() | ||
|
||
for _, val := range someMap { | ||
sink(val) // $ hasValueFlow="val" | ||
} | ||
} | ||
|
||
func testLiteral() { | ||
someMap := map[string]string{"someKey": source()} | ||
|
||
for _, val := range someMap { | ||
sink(val) // $ hasValueFlow="val" | ||
} | ||
} |