File tree Expand file tree Collapse file tree 4 files changed +54
-2
lines changed
go/ql/test/library-tests/semmle/go/dataflow Expand file tree Collapse file tree 4 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ func source() string {
4
4
return "untrusted data"
5
5
}
6
6
7
- func sink (string ) {
7
+ func sink (any ) {
8
8
}
9
9
10
10
func sliceToArray (p []string ) [1 ]string {
@@ -15,11 +15,15 @@ func main() {
15
15
// Test the new slice->array conversion permitted in Go 1.20
16
16
var a [4 ]string
17
17
a [0 ] = source ()
18
- alias := sliceToArray (a [:])
18
+ alias := [ 2 ] string (a [:])
19
19
sink (alias [0 ]) // $ hasTaintFlow="index expression"
20
+ sink (alias [1 ]) // $ SPURIOUS: hasTaintFlow="index expression" // we don't distinguish different elements of arrays or slices
21
+ sink (alias ) // $ hasTaintFlow="alias"
20
22
21
23
// Compare with the standard dataflow support for arrays
22
24
var b [4 ]string
23
25
b [0 ] = source ()
24
26
sink (b [0 ]) // $ hasValueFlow="index expression"
27
+ sink (b [1 ]) // $ SPURIOUS: hasValueFlow="index expression" // we don't distinguish different elements of arrays or slices
28
+ sink (b ) // $ hasTaintFlow="b"
25
29
}
Original file line number Diff line number Diff line change
1
+ import go
2
+ import TestUtilities.InlineFlowTest
3
+ import DefaultFlowTest
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ func source () string {
4
+ return "untrusted data"
5
+ }
6
+
7
+ func sink (any ) {
8
+ }
9
+
10
+ func main () {
11
+ }
12
+
13
+ // Value flow with array content through slice expressions
14
+
15
+ func arrayBase (base [4 ]string ) {
16
+ base [1 ] = source ()
17
+ slice := base [1 :4 ]
18
+ sink (slice [0 ]) // $ hasTaintFlow="index expression"
19
+ sink (slice [1 ]) // $ SPURIOUS: hasTaintFlow="index expression" // we don't distinguish different elements of arrays or slices
20
+ sink (slice ) // $ hasTaintFlow="slice"
21
+ }
22
+
23
+ func arrayPointerBase (base * [4 ]string ) {
24
+ base [1 ] = source ()
25
+ slice := base [1 :4 ]
26
+ sink (slice [0 ]) // $ hasTaintFlow="index expression"
27
+ sink (slice [1 ]) // $ SPURIOUS: hasTaintFlow="index expression" // we don't distinguish different elements of arrays or slices
28
+ sink (slice ) // $ hasTaintFlow="slice"
29
+ }
30
+
31
+ func sliceBase (base []string ) {
32
+ base [1 ] = source ()
33
+ slice := base [1 :4 ]
34
+ sink (slice [0 ]) // $ hasTaintFlow="index expression"
35
+ sink (slice [1 ]) // $ SPURIOUS: hasTaintFlow="index expression" // we don't distinguish different elements of arrays or slices
36
+ sink (slice ) // $ hasTaintFlow="slice"
37
+ }
38
+
39
+ func slicePointerBase (base * []string ) {
40
+ (* base )[1 ] = source ()
41
+ slice := (* base )[1 :4 ]
42
+ sink (slice [0 ]) // $ hasTaintFlow="index expression"
43
+ sink (slice [1 ]) // $ SPURIOUS: hasTaintFlow="index expression" // we don't distinguish different elements of arrays or slices
44
+ sink (slice ) // $ hasTaintFlow="slice"
45
+ }
You can’t perform that action at this time.
0 commit comments