|
| 1 | +package main |
| 2 | + |
| 3 | +var globalScalar any |
| 4 | +var globalArray [1]any |
| 5 | +var globalSlice []any |
| 6 | +var globalMap1 map[any]any |
| 7 | +var globalMap2 map[any]any |
| 8 | + |
| 9 | +func source(n int) any { return n } |
| 10 | + |
| 11 | +func sink(x any) {} |
| 12 | + |
| 13 | +func main() { |
| 14 | + test1() |
| 15 | + test2() |
| 16 | + sink(globalScalar) // $ hasValueFlow="globalScalar (from source 0)" MISSING: hasValueFlow="globalScalar (from source 10)" |
| 17 | + sink(globalArray[0]) // $ MISSING: hasValueFlow="index expression (from source 1)" hasValueFlow="index expression (from source 11)" |
| 18 | + sink(globalSlice[0]) // $ MISSING: hasValueFlow="index expression (from source 2)" hasValueFlow="index expression (from source 12)" |
| 19 | + for val := range globalMap1 { |
| 20 | + sink(val) // $ MISSING: hasValueFlow="val (from source 3)" hasValueFlow="val (from source 13)" |
| 21 | + } |
| 22 | + for _, val := range globalMap2 { |
| 23 | + sink(val) // $ MISSING: hasValueFlow="val (from source 4)" hasValueFlow="val (from source 14)" |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func test1() { |
| 28 | + globalScalar = source(0) |
| 29 | + globalArray[0] = source(1) |
| 30 | + globalSlice[0] = source(2) |
| 31 | + globalMap1[source(3)] = nil |
| 32 | + globalMap2[""] = source(4) |
| 33 | +} |
| 34 | + |
| 35 | +func test2() { |
| 36 | + taintScalar(&globalScalar, 10) |
| 37 | + taintArray(globalArray, 11) |
| 38 | + taintSlice(globalSlice, 12) |
| 39 | + taintMapKey(globalMap1, 13) |
| 40 | + taintMapValue(globalMap2, 14) |
| 41 | +} |
| 42 | + |
| 43 | +func taintScalar(x *any, n int) { |
| 44 | + *x = source(n) |
| 45 | +} |
| 46 | + |
| 47 | +func taintArray(x [1]any, n int) { |
| 48 | + x[0] = source(n) |
| 49 | +} |
| 50 | + |
| 51 | +func taintSlice(x []any, n int) { |
| 52 | + x[0] = source(n) |
| 53 | +} |
| 54 | + |
| 55 | +func taintMapKey(x map[any]any, n int) { |
| 56 | + x[source(n)] = "" |
| 57 | +} |
| 58 | + |
| 59 | +func taintMapValue(x map[any]any, n int) { |
| 60 | + x[""] = source(n) |
| 61 | +} |
0 commit comments