Skip to content

Commit 803ed20

Browse files
authored
Merge pull request #14778 from owen-mc/go/improve-value-flow-through-arrays
Go: improve value flow through arrays
2 parents b8f0f85 + 83d1fc3 commit 803ed20

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* A bug has been fixed that meant that value flow through an array was not tracked correctly in some circumstances. Taint flow was tracked correctly.

go/ql/lib/semmle/go/Expr.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,16 +724,19 @@ class GenericTypeInstantiationExpr extends Expr {
724724
* ```go
725725
* a[1:3]
726726
* a[1:3:5]
727+
* a[1:]
728+
* a[:3]
729+
* a[:]
727730
* ```
728731
*/
729732
class SliceExpr extends @sliceexpr, Expr {
730733
/** Gets the base of this slice expression. */
731734
Expr getBase() { result = this.getChildExpr(0) }
732735

733-
/** Gets the lower bound of this slice expression. */
736+
/** Gets the lower bound of this slice expression, if any. */
734737
Expr getLow() { result = this.getChildExpr(1) }
735738

736-
/** Gets the upper bound of this slice expression. */
739+
/** Gets the upper bound of this slice expression, if any. */
737740
Expr getHigh() { result = this.getChildExpr(2) }
738741

739742
/** Gets the maximum of this slice expression, if any. */

go/ql/lib/semmle/go/dataflow/internal/ContainerFlow.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ predicate containerStoreStep(Node node1, Node node2, Content c) {
2121
node2.getType() instanceof SliceType
2222
) and
2323
(
24-
exists(Write w | w.writesElement(node2, _, node1))
24+
exists(Write w | w.writesElement(node2.(PostUpdateNode).getPreUpdateNode(), _, node1))
2525
or
2626
node1 = node2.(ImplicitVarargsSlice).getCallNode().getAnImplicitVarargsArgument()
2727
)

go/ql/test/library-tests/semmle/go/dataflow/ArrayConversion/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ func main() {
2121
// Compare with the standard dataflow support for arrays
2222
var b [4]string
2323
b[0] = source()
24-
sink(b[0]) // $ hasTaintFlow="index expression"
24+
sink(b[0]) // $ hasValueFlow="index expression"
2525
}

go/ql/test/library-tests/semmle/go/frameworks/Beego/ReflectedXss.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ edges
4747
| test.go:246:15:246:36 | call to GetString | test.go:249:21:249:29 | untrusted |
4848
| test.go:259:23:259:44 | call to GetCookie | test.go:259:16:259:45 | type conversion |
4949
| test.go:270:62:270:83 | call to GetCookie | test.go:270:55:270:84 | type conversion |
50+
| test.go:275:2:275:40 | ... := ...[0] | test.go:278:21:278:28 | index expression |
5051
| test.go:275:2:275:40 | ... := ...[0] | test.go:283:44:283:60 | selection of Filename |
5152
| test.go:275:2:275:40 | ... := ...[0] | test.go:284:38:284:49 | genericFiles |
5253
| test.go:275:2:275:40 | ... := ...[0] | test.go:285:37:285:48 | genericFiles |
@@ -61,6 +62,8 @@ edges
6162
| test.go:275:2:275:40 | ... := ...[0] | test.go:301:39:301:50 | genericFiles |
6263
| test.go:275:2:275:40 | ... := ...[0] | test.go:302:40:302:51 | genericFiles |
6364
| test.go:275:2:275:40 | ... := ...[0] | test.go:303:39:303:50 | genericFiles |
65+
| test.go:276:2:276:13 | definition of genericFiles [array] | test.go:297:51:297:62 | genericFiles [array] |
66+
| test.go:278:21:278:28 | index expression | test.go:276:2:276:13 | definition of genericFiles [array] |
6467
| test.go:283:44:283:60 | selection of Filename | test.go:283:21:283:61 | call to GetDisplayString |
6568
| test.go:284:21:284:53 | call to SliceChunk | test.go:284:21:284:92 | selection of Filename |
6669
| test.go:284:38:284:49 | genericFiles | test.go:284:21:284:53 | call to SliceChunk |
@@ -77,6 +80,7 @@ edges
7780
| test.go:296:21:296:61 | call to SliceMerge | test.go:296:21:296:97 | selection of Filename |
7881
| test.go:296:49:296:60 | genericFiles | test.go:296:21:296:61 | call to SliceMerge |
7982
| test.go:297:21:297:66 | call to SlicePad | test.go:297:21:297:102 | selection of Filename |
83+
| test.go:297:51:297:62 | genericFiles [array] | test.go:297:51:297:65 | index expression |
8084
| test.go:297:51:297:65 | index expression | test.go:297:21:297:66 | call to SlicePad |
8185
| test.go:298:21:298:66 | call to SlicePad | test.go:298:21:298:102 | selection of Filename |
8286
| test.go:298:36:298:47 | genericFiles | test.go:298:21:298:66 | call to SlicePad |
@@ -177,6 +181,8 @@ nodes
177181
| test.go:270:55:270:84 | type conversion | semmle.label | type conversion |
178182
| test.go:270:62:270:83 | call to GetCookie | semmle.label | call to GetCookie |
179183
| test.go:275:2:275:40 | ... := ...[0] | semmle.label | ... := ...[0] |
184+
| test.go:276:2:276:13 | definition of genericFiles [array] | semmle.label | definition of genericFiles [array] |
185+
| test.go:278:21:278:28 | index expression | semmle.label | index expression |
180186
| test.go:283:21:283:61 | call to GetDisplayString | semmle.label | call to GetDisplayString |
181187
| test.go:283:44:283:60 | selection of Filename | semmle.label | selection of Filename |
182188
| test.go:284:21:284:53 | call to SliceChunk | semmle.label | call to SliceChunk |
@@ -202,6 +208,7 @@ nodes
202208
| test.go:296:49:296:60 | genericFiles | semmle.label | genericFiles |
203209
| test.go:297:21:297:66 | call to SlicePad | semmle.label | call to SlicePad |
204210
| test.go:297:21:297:102 | selection of Filename | semmle.label | selection of Filename |
211+
| test.go:297:51:297:62 | genericFiles [array] | semmle.label | genericFiles [array] |
205212
| test.go:297:51:297:65 | index expression | semmle.label | index expression |
206213
| test.go:298:21:298:66 | call to SlicePad | semmle.label | call to SlicePad |
207214
| test.go:298:21:298:102 | selection of Filename | semmle.label | selection of Filename |

0 commit comments

Comments
 (0)