8000 Test calls through variables · github/codeql-go@ba147e8 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit ba147e8

Browse files
owen-mcsmowton
authored andcommitted
Test calls through variables
The tests which involve a flow through a receiver with a non-trivial access path currently don't give the right result. This should be fixed in a follow-up issue.
1 parent 4a9aeac commit ba147e8

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

ql/test/library-tests/semmle/go/dataflow/GenericFunctionsAndTypes/genericfunctions.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ func genericSink2[T any](t T, u string) {
1717
sink(u) // $ hasValueFlow="u"
1818
}
1919

20+
func genericSink3[T any](t T, u string) {
21+
sink(u) // $ hasValueFlow="u"
22+
}
23+
2024
func test() {
2125
var x struct {
2226
x1 int
@@ -30,6 +34,11 @@ func test() {
3034
s := genericSource[int8](2)
3135
sink(s) // $ hasValueFlow="s"
3236
}
37+
{
38+
f := genericSource[int8]
39+
s := f(2)
40+
sink(s) // $ hasValueFlow="s"
41+
}
3342
{
3443
s := genericIdentity(source())
3544
sink(s) // $ hasValueFlow="s"
@@ -38,6 +47,11 @@ func test() {
3847
s := genericIdentity[string](source())
3948
sink(s) // $ hasValueFlow="s"
4049
}
50+
{
51+
f := genericIdentity[string]
52+
s := f(source())
53+
sink(s) // $ hasValueFlow="s"
54+
}
4155
{
4256
s := source()
4357
genericSink1(x, s)
@@ -46,4 +60,9 @@ func test() {
4660
s := source()
4761
genericSink2[uint16](3, s)
4862
}
63+
{
64+
s := source()
65+
f := genericSink3[uint16]
66+
f(3, s)
67+
}
4968
}

ql/test/library-tests/semmle/go/dataflow/GenericFunctionsAndTypes/generictypesandmethods.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,33 @@ func main() {
3737
gs1 := GenericStruct1[string]{""}
3838
sink(gs1.Identity(source())) // $ hasValueFlow="call to Identity"
3939
}
40+
{
41+
gs1 := GenericStruct1[string]{""}
42+
f := gs1.Identity
43+
sink(f(source())) // $ hasValueFlow="call to f"
44+
}
4045
{
4146
gs1 := GenericStruct1[string]{""}
4247
gs1.Field = source()
4348
sink(gs1.Getter()) // $ hasValueFlow="call to Getter"
4449
}
50+
{
51+
gs1 := GenericStruct1[string]{""}
52+
gs1.Field = source()
53+
f := gs1.Getter
54+
sink(f()) // $ MISSING: hasValueFlow="call to f"
55+
}
4556
{
4657
gs1 := GenericStruct1[string]{""}
4758
gs1.Setter(source())
4859
sink(gs1.Field) // $ hasValueFlow="selection of Field"
4960
}
61+
{
62+
gs1 := GenericStruct1[string]{""}
63+
f := gs1.Setter
64+
f(source())
65+
sink(gs1.Field) // $ MISSING: hasValueFlow="selection of Field"
66+
}
5067

5168
{
5269
gs2 := GenericStruct2[string, string]{source(), ""}
@@ -56,16 +73,33 @@ func main() {
5673
gs2 := GenericStruct2[string, string]{"", ""}
5774
sink(gs2.Identity1(source())) // $ hasValueFlow="call to Identity1"
5875
}
76+
{
77+
gs2 := GenericStruct2[string, string]{"", ""}
78+
f := gs2.Identity1
79+
sink(f(source())) // $ hasValueFlow="call to f"
80+
}
5981
{
6082
gs2 := GenericStruct2[string, string]{"", ""}
6183
gs2.Field1 = source()
6284
sink(gs2.Getter1()) // $ hasValueFlow="call to Getter1"
6385
}
86+
{
87+
gs2 := GenericStruct2[string, string]{"", ""}
88+
gs2.Field1 = source()
89+
f := gs2.Getter1
90+
sink(f()) // $ MISSING: hasValueFlow="call to f"
91+
}
6492
{
6593
gs2 := GenericStruct2[string, string]{"", ""}
6694
gs2.Setter1(source())
6795
sink(gs2.Field1) // $ hasValueFlow="selection of Field1"
6896
}
97+
{
98+
gs2 := GenericStruct2[string, string]{"", ""}
99+
f := gs2.Setter1
100+
f(source())
101+
sink(gs2.Field1) // $ MISSING: hasValueFlow="selection of Field1"
102+
}
69103

70104
{
71105
gs2 := GenericStruct2[string, string]{"", source()}
@@ -75,14 +109,31 @@ func main() {
75109
gs2 := GenericStruct2[string, string]{"", ""}
76110
sink(gs2.Identity2(source())) // $ hasValueFlow="call to Identity2"
77111
}
112+
{
113+
gs2 := GenericStruct2[string, string]{"", ""}
114+
f := gs2.Identity2
115+
sink(f(source())) // $ hasValueFlow="call to f"
116+
}
78117
{
79118
gs2 := GenericStruct2[string, string]{"", ""}
80119
gs2.Field2 = source()
81120
sink(gs2.Getter2()) // $ hasValueFlow="call to Getter2"
82121
}
122+
{
123+
gs2 := GenericStruct2[string, string]{"", ""}
124+
gs2.Field2 = source()
125+
f := gs2.Getter2
126+
sink(f()) // $ MISSING: hasValueFlow="call to f"
127+
}
83128
{
84129
gs2 := GenericStruct2[string, string]{"", ""}
85130
gs2.Setter2(source())
86131
sink(gs2.Field2) // $ hasValueFlow="selection of Field2"
87132
}
133+
{
134+
gs2 := GenericStruct2[string, string]{"", ""}
135+
f := gs2.Setter2
136+
f(source())
137+
sink(gs2.Field2) // $ MISSING: hasValueFlow="selection of Field2"
138+
}
88139
}

0 commit comments

Comments
 (0)
0