Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab5e1f8

Browse files
committed
Fix models for min and max and improve tests
Although the documentation makes them look variadic (and generic), they are actually special-cased in the compiler. Like all built-in functions they don't have a signature type, but the type of `min(a, b, c)` is `func(int, int, int) int` and not `func(int, ...int) int`. Go doesn't allow open-ended ranges for argument indices in models-as-data specifications (though Ruby and Python do), so I've used `1..1000`.
1 parent f7e6bf7 commit ab5e1f8

5 files changed

Lines changed: 36 additions & 4 deletions

File tree

go/ql/lib/ext/builtin.model.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ extensions:
66
- ["", "", False, "append", "", "", "Argument[0].ArrayElement", "ReturnValue.ArrayElement", "value", "manual"]
77
- ["", "", False, "append", "", "", "Argument[1].ArrayElement", "ReturnValue.ArrayElement", "value", "manual"]
88
- ["", "", False, "copy", "", "", "Argument[1].ArrayElement", "Argument[0].ArrayElement", "value", "manual"]
9-
- ["", "", False, "max", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
10-
- ["", "", False, "max", "", "", "Argument[1]", "ReturnValue", "value", "manual"]
11-
- ["", "", False, "min", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
12-
- ["", "", False, "min", "", "", "Argument[1]", "ReturnValue", "value", "manual"]
9+
- ["", "", False, "max", "", "", "Argument[0..1000]", "ReturnValue", "value", "manual"]
10+
- ["", "", False, "min", "", "", "Argument[0..1000]", "ReturnValue", "value", "manual"]

go/ql/test/library-tests/semmle/go/dataflow/ExternalValueFlow/sinks.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ invalidModelRow
3434
| test.go:170:17:170:20 | arg1 | qltest |
3535
| test.go:170:23:170:26 | arg2 | qltest |
3636
| test.go:170:29:170:32 | arg3 | qltest |
37+
| test.go:173:10:173:26 | call to max | qltest |
38+
| test.go:174:10:174:26 | call to max | qltest |
39+
| test.go:175:10:175:26 | call to max | qltest |
40+
| test.go:176:10:176:26 | call to min | qltest |
41+
| test.go:177:10:177:26 | call to min | qltest |
42+
| test.go:178:10:178:26 | call to min | qltest |

go/ql/test/library-tests/semmle/go/dataflow/ExternalValueFlow/steps.expected

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,21 @@ invalidModelRow
1414
| test.go:74:13:74:25 | type assertion | test.go:74:12:74:40 | call to StepQualRes |
1515
| test.go:78:3:78:15 | type assertion | test.go:77:6:77:11 | definition of taint6 |
1616
| test.go:81:34:81:36 | src | test.go:81:12:81:37 | call to StepArgResNoQual |
17+
| test.go:173:14:173:19 | srcInt | test.go:173:10:173:26 | call to max |
18+
| test.go:173:22:173:22 | 0 | test.go:173:10:173:26 | call to max |
19+
| test.go:173:25:173:25 | 1 | test.go:173:10:173:26 | call to max |
20+
| test.go:174:14:174:14 | 0 | test.go:174:10:174:26 | call to max |
21+
| test.go:174:17:174:22 | srcInt | test.go:174:10:174:26 | call to max |
22+
| test.go:174:25:174:25 | 1 | test.go:174:10:174:26 | call to max |
23+
| test.go:175:14:175:14 | 0 | test.go:175:10:175:26 | call to max |
24+
| test.go:175:17:175:17 | 1 | test.go:175:10:175:26 | call to max |
25+
| test.go:175:20:175:25 | srcInt | test.go:175:10:175:26 | call to max |
26+
| test.go:176:14:176:19 | srcInt | test.go:176:10:176:26 | call to min |
27+
| test.go:176:22:176:22 | 0 | test.go:176:10:176:26 | call to min |
28+
| test.go:176:25:176:25 | 1 | test.go:176:10:176:26 | call to min |
29+
| test.go:177:14:177:14 | 0 | test.go:177:10:177:26 | call to min |
30+
| test.go:177:17:177:22 | srcInt | test.go:177:10:177:26 | call to min |
31+
| test.go:177:25:177:25 | 1 | test.go:177:10:177:26 | call to min |
32+
| test.go:178:14:178:14 | 0 | test.go:178:10:178:26 | call to min |
33+
| test.go:178:17:178:17 | 1 | test.go:178:10:178:26 | call to min |
34+
| test.go:178:20:178:25 | srcInt | test.go:178:10:178:26 | call to min |

go/ql/test/library-tests/semmle/go/dataflow/ExternalValueFlow/test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,12 @@ func simpleflow() {
168168
arg3 := src
169169
arg4 := src
170170
b.SinkManyArgs(arg1, arg2, arg3, arg4) // $ hasValueFlow="arg1" hasValueFlow="arg2" hasValueFlow="arg3"
171+
172+
var srcInt int = src.(int)
173+
b.Sink1(max(srcInt, 0, 1)) // $ hasValueFlow="call to max"
174+
b.Sink1(max(0, srcInt, 1)) // $ hasValueFlow="call to max"
175+
b.Sink1(max(0, 1, srcInt)) // $ hasValueFlow="call to max"
176+
b.Sink1(min(srcInt, 0, 1)) // $ hasValueFlow="call to min"
177+
b.Sink1(min(0, srcInt, 1)) // $ hasValueFlow="call to min"
178+
b.Sink1(min(0, 1, srcInt)) // $ hasValueFlow="call to min"
171179
}

go/ql/test/library-tests/semmle/go/dataflow/FlowSteps/LocalFlowStep.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@
127127
| main.go:64:7:64:18 | call to min | main.go:64:2:64:2 | definition of a |
128128
| main.go:64:11:64:11 | x | main.go:64:7:64:18 | call to min |
129129
| main.go:64:14:64:14 | y | main.go:64:7:64:18 | call to min |
130+
| main.go:64:17:64:17 | z | main.go:64:7:64:18 | call to min |
130131
| main.go:65:2:65:2 | definition of b | main.go:66:12:66:12 | b |
131132
| main.go:65:7:65:18 | call to max | main.go:65:2:65:2 | definition of b |
132133
| main.go:65:11:65:11 | x | main.go:65:7:65:18 | call to max |
133134
| main.go:65:14:65:14 | y | main.go:65:7:65:18 | call to max |
135+
| main.go:65:17:65:17 | z | main.go:65:7:65:18 | call to max |
134136
| strings.go:8:12:8:12 | argument corresponding to s | strings.go:8:12:8:12 | definition of s |
135137
| strings.go:8:12:8:12 | definition of s | strings.go:9:24:9:24 | s |
136138
| strings.go:8:12:8:12 | definition of s | strings.go:10:27:10:27 | s |

0 commit comments

Comments
 (0)