Skip to content

Commit 6118886

Browse files
owen-mcCopilot
andcommitted
Go: model maps package (skipping functions that involve iterating over a function)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e37391e commit 6118886

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
# DeleteFunc does not need to be modeled since it only removes key/value pairs from m in place and does not return a value
13+
# Equal does not need to be modeled since it returns a bool
14+
# EqualFunc does not need to be modeled since it returns a bool
15+
# Insert should be modeled when we have a way to model iterators
16+
# Keys should be modeled when we have a way to model iterators
17+
# 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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"maps"
5+
)
6+
7+
func TaintStepTest_MapsCloneValue(fromString string) string {
8+
m := map[string]string{"key": fromString}
9+
clone := maps.Clone(m)
10+
return clone["key"]
11+
}
12+
13+
func TaintStepTest_MapsCloneKey(fromString string) string {
14+
m := map[string]string{fromString: "value"}
15+
clone := maps.Clone(m)
16+
for k := range clone {
17+
return k
18+
}
19+
return ""
20+
}
21+
22+
func TaintStepTest_MapsCopyValue(fromString string) string {
23+
src := map[string]string{"key": fromString}
24+
dst := map[string]string{}
25+
maps.Copy(dst, src)
26+
return dst["key"]
27+
}
28+
29+
func TaintStepTest_MapsCopyKey(fromString string) string {
30+
src := map[string]string{fromString: "value"}
31+
dst := map[string]string{}
32+
maps.Copy(dst, src)
33+
for k := range dst {
34+
return k
35+
}
36+
return ""
37+
}
38+
39+
func RunAllTaints_Maps() {
40+
{
41+
source := newSource(0).(string)
42+
out := TaintStepTest_MapsCloneValue(source)
43+
sink(0, out)
44+
}
45+
{
46+
source := newSource(1).(string)
47+
out := TaintStepTest_MapsCloneKey(source)
48+
sink(1, out)
49+
}
50+
{
51+
source := newSource(2).(string)
52+
out := TaintStepTest_MapsCopyValue(source)
53+
sink(2, out)
54+
}
55+
{
56+
source := newSource(3).(string)
57+
out := TaintStepTest_MapsCopyKey(source)
58+
sink(3, out)
59+
}
60+
}

0 commit comments

Comments
 (0)