Skip to content

Commit d822d14

Browse files
committed
Test deeply ntested taint
1 parent 14e0ce8 commit d822d14

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

go/ql/test/library-tests/semmle/go/frameworks/serialization/texttemplate.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ type Inner3 struct {
1717
Data string
1818
}
1919

20+
type HasInner3Slice struct {
21+
Slice []Inner3
22+
}
23+
2024
type Outer struct {
2125
SliceField []Inner1
2226
PtrField *Inner2
2327
MapField map[string]Inner3
28+
DeepField HasInner3Slice
2429
}
2530

2631
func source(n int) string { return "dummy" }
@@ -31,8 +36,10 @@ func test() {
3136
source1 := source(1)
3237
source2 := source(2)
3338
source3 := source(3)
39+
source4 := source(4)
3440

35-
toSerialize := Outer{[]Inner1{{source1}}, &Inner2{source2}, map[string]Inner3{"key": {source3}}}
41+
toSerialize := Outer{[]Inner1{{source1}}, &Inner2{source2}, map[string]Inner3{"key": {source3}},
42+
HasInner3Slice{[]Inner3{{source4}}}}
3643
buff1 := new(bytes.Buffer)
3744
buff2 := new(bytes.Buffer)
3845
bytes1 := make([]byte, 10)
@@ -41,13 +48,13 @@ func test() {
4148
tmpl, _ := template.New("test").Parse("Template text goes here (irrelevant for test)")
4249
tmpl.ExecuteTemplate(buff1, "test", toSerialize)
4350
buff1.Read(bytes1)
44-
sink(bytes1) // $ hasTaintFlow=1 hasTaintFlow=2 hasTaintFlow=3
51+
sink(bytes1) // $ hasTaintFlow=1 hasTaintFlow=2 hasTaintFlow=3 hasTaintFlow=4
4552

4653
// Read `buff2` via an `any`-typed variable, to ensure the static type of the argument to tmpl.Execute makes no difference to the result
4754
var toSerializeAsAny any
4855
toSerializeAsAny = toSerialize
4956
tmpl.Execute(buff2, toSerializeAsAny)
5057
buff2.Read(bytes2)
51-
sink(bytes2) // $ hasTaintFlow=1 hasTaintFlow=2 hasTaintFlow=3
58+
sink(bytes2) // $ hasTaintFlow=1 hasTaintFlow=2 hasTaintFlow=3 hasTaintFlow=4
5259

5360
}

0 commit comments

Comments
 (0)