Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit e3501dd

Browse files
author
Max Schaefer
committed
Introduce more post-update nodes.
To model (taint) flow through functions, we introduce post-update nodes for arguments (including receivers), but only if that argument is mutable. However, previously our criterion for determining whether an argument is mutable was a little too restrictive. In particular, we would not consider a struct-typed argument as mutable, since structs are passed by value. While this is reasonable for data flow, it is unnecessarily restrictive for taint, since it makes perfect sense to track deep taint through structs. So instead we now turn things round and instead consider _all_ types to be mutable except for primitive types (booleans, numbers, and strings).
1 parent 0dd7676 commit e3501dd

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

ql/src/semmle/go/dataflow/internal/DataFlowUtil.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,10 @@ class ArgumentNode extends Node {
464464
*/
465465
predicate mutableType(Type tp) {
466466
exists(Type underlying | underlying = tp.getUnderlyingType() |
467-
underlying instanceof ArrayType or
468-
underlying instanceof SliceType or
469-
underlying instanceof MapType or
470-
underlying instanceof PointerType or
471-
underlying instanceof InterfaceType
467+
not underlying instanceof BoolType and
468+
not underlying instanceof NumericType and
469+
not underlying instanceof StringType and
470+
not underlying instanceof LiteralType
472471
)
473472
}
474473

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| file://:0:0:0:0 | ReadFrom | tst.go:10:23:10:28 | reader | tst.go:9:2:9:12 | definition of bytesBuffer |
2+
| file://:0:0:0:0 | Reset | reset.go:12:15:12:20 | source | reset.go:11:6:11:11 | definition of reader |

ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionOutput_getExitNode.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
| parameter 0 | reset.go:12:2:12:21 | call to Reset | reset.go:9:2:9:7 | definition of source |
22
| parameter 0 | tst.go:10:2:10:29 | call to ReadFrom | tst.go:8:12:8:17 | definition of reader |
3+
| receiver | main.go:53:14:53:21 | call to bump | main.go:52:2:52:2 | definition of c |
4+
| receiver | reset.go:12:2:12:21 | call to Reset | reset.go:11:6:11:11 | definition of reader |
35
| receiver | tst.go:10:2:10:29 | call to ReadFrom | tst.go:9:2:9:12 | definition of bytesBuffer |
46
| result | main.go:51:2:51:14 | call to op | main.go:51:2:51:14 | call to op |
57
| result | main.go:53:2:53:22 | call to op2 | main.go:53:2:53:22 | call to op2 |

0 commit comments

Comments
 (0)