Skip to content

Commit 1a5aefd

Browse files
committed
Model maps
1 parent 8a95291 commit 1a5aefd

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎go/ql/lib/ext/maps.model.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/go-all
4+
extensible: summaryModel
5+
data:
6+
# All should be modeled when we have a way to model iterators
7+
- ["maps", "", False, "Clone", "", "", "Argument[0].MapKey", "ReturnValue.MapKey", "value", "manual"]
8+
- ["maps", "", False, "Clone", "", "", "Argument[0].MapValue", "ReturnValue.MapValue", "value", "manual"]
9+
# Collect should be modeled when we have a way to model iterators
10+
- ["maps", "", False, "Copy", "", "", "Argument[1].MapKey", "Argument[0].MapKey", "value", "manual"]
11+
- ["maps", "", False, "Copy", "", "", "Argument[1].MapValue", "Argument[0].MapValue", "value", "manual"]
12+
# Insert should be modeled when we have a way to model iterators
13+
# Keys should be modeled when we have a way to model iterators
14+
# Values should be modeled when we have a way to model iterators
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added value flow models for functions in the `maps` package which do not involve the `iter` package.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import "maps"
4+
5+
func TaintStepTest_MapsCloneKey(fromString string) string {
6+
toMap := maps.Clone(map[string]int{fromString: 0})
7+
for key := range toMap {
8+
return key
9+
}
10+
return ""
11+
}
12+
13+
func TaintStepTest_MapsCloneValue(fromString string) string {
14+
toMap := maps.Clone(map[string]string{"key": fromString})
15+
return toMap["key"]
16+
}
17+
18+
func TaintStepTest_MapsCopyKey(fromString string) string {
19+
toMap := map[string]int{}
20+
maps.Copy(toMap, map[string]int{fromString: 0})
21+
for key := range toMap {
22+
return key
23+
}
24+
return ""
25+
}
26+
27+
func TaintStepTest_MapsCopyValue(fromString string) string {
28+
toMap := map[string]string{}
29+
maps.Copy(toMap, map[string]string{"key": fromString})
30+
return toMap["key"]
31+
}
32+
33+
func RunAllTaints_Maps() {
34+
{
35+
source := newSource(0).(string)
36+
out := TaintStepTest_MapsCloneKey(source)
37+
sink(0, out)
38+
}
39+
{
40+
source := newSource(1).(string)
41+
out := TaintStepTest_MapsCloneValue(source)
42+
sink(1, out)
43+
}
44+
{
45+
source := newSource(2).(string)
46+
out := TaintStepTest_MapsCopyKey(source)
47+
sink(2, out)
48+
}
49+
{
50+
source := newSource(3).(string)
51+
out := TaintStepTest_MapsCopyValue(source)
52+
sink(3, out)
53+
}
54+
}

0 commit comments

Comments
 (0)