Skip to content

Commit c5ffdee

Browse files
committed
Go: restore data flow through pointer assignment targets
Evaluate the operand of a skipped pointer LHS and create post-update nodes for the full access path.
1 parent 6c6f0a9 commit c5ffdee

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ module CfgImpl {
106106
not skipCfg(n) and
107107
result = n.getChild(index)
108108
or
109+
exists(Go::Assignment assgn, Go::Expr lhs |
110+
n = assgn and lhs = assgn.getLhs(_) and lhs = n.getChild(index) and skipCfg(lhs)
111+
|
112+
result = lhs.(Go::StarExpr).getBase()
113+
or
114+
result = lhs.(Go::DerefExpr).getOperand()
115+
)
116+
or
109117
// The body block of a switch (expression or type) is transparent (see
110118
// `skipCfg`), so it is not itself a child and contributes no children.
111119
// Expose the case clauses directly as children of the switch instead,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ module Public {
772772
private IR::Instruction getADirectlyWrittenInsn() {
773773
exists(Write w | w.writesComponentInstruction(result, _))
774774
or
775+
result = any(Write w).getLhs().(IR::PointerTarget).getBase()
776+
or
775777
result = IR::evalExprInstruction(any(SendStmt s).getChannel())
776778
}
777779

go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2776,9 +2776,12 @@
27762776
| stmts3.go:14:13:14:13 | x | stmts3.go:14:21:16:1 | block statement |
27772777
| stmts3.go:14:21:16:1 | After block statement | stmts3.go:14:1:16:1 | Normal Exit |
27782778
| stmts3.go:14:21:16:1 | block statement | stmts3.go:15:2:15:8 | ... = ... |
2779-
| stmts3.go:15:2:15:8 | ... = ... | stmts3.go:15:7:15:8 | Before 42 |
2779+
| stmts3.go:15:2:15:8 | ... = ... | stmts3.go:15:3:15:3 | Before x |
27802780
| stmts3.go:15:2:15:8 | After ... = ... | stmts3.go:14:21:16:1 | After block statement |
27812781
| stmts3.go:15:2:15:8 | assign:0 ... = ... | stmts3.go:15:2:15:8 | After ... = ... |
2782+
| stmts3.go:15:3:15:3 | After x | stmts3.go:15:7:15:8 | Before 42 |
2783+
| stmts3.go:15:3:15:3 | Before x | stmts3.go:15:3:15:3 | x |
2784+
| stmts3.go:15:3:15:3 | x | stmts3.go:15:3:15:3 | After x |
27822785
| stmts3.go:15:7:15:8 | 42 | stmts3.go:15:7:15:8 | After 42 |
27832786
| stmts3.go:15:7:15:8 | After 42 | stmts3.go:15:2:15:8 | assign:0 ... = ... |
27842787
| stmts3.go:15:7:15:8 | Before 42 | stmts3.go:15:7:15:8 | 42 |

0 commit comments

Comments
 (0)