From 2d4f17c91cf2a61b26939759d9f09bac1223afdf Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Tue, 22 Sep 2020 09:08:17 +0100 Subject: [PATCH] Ensure result inputs always have an entry node. --- ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll | 2 +- .../FunctionInput_getEntryNode.expected | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll b/ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll index df40f273213..140fe260fb7 100644 --- a/ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll +++ b/ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll @@ -116,7 +116,7 @@ private class ResultInput extends FunctionInput, TInResult { | // if the result is assigned to an SSA variable, we want to propagate mutations backwards // through that variable - exists(DataFlow::SsaNode ssa | ssa.getInit() = pred | result = ssa.(DataFlow::PostUpdateNode)) + exists(DataFlow::SsaNode ssa | ssa.getInit() = pred | result = ssa) or // otherwise the entry node is simply the result not exists(DataFlow::SsaNode ssa | ssa.getInit() = pred) and diff --git a/ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionInput_getEntryNode.expected b/ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionInput_getEntryNode.expected index b06f3d29a56..8c3a2b043dc 100644 --- a/ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionInput_getEntryNode.expected +++ b/ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionInput_getEntryNode.expected @@ -25,9 +25,15 @@ | result | main.go:53:2:53:22 | call to op2 | main.go:53:2:53:22 | call to op2 | | result | main.go:53:14:53:21 | call to bump | main.go:53:14:53:21 | call to bump | | result | tst2.go:10:9:10:26 | call to NewEncoder | tst2.go:10:9:10:26 | call to NewEncoder | +| result | tst2.go:10:9:10:39 | call to Encode | tst2.go:10:2:10:4 | definition of err | | result | tst.go:9:17:9:33 | call to new | tst.go:9:2:9:12 | definition of bytesBuffer | | result 0 | main.go:51:2:51:14 | call to op | main.go:51:2:51:14 | call to op | | result 0 | main.go:53:2:53:22 | call to op2 | main.go:53:2:53:22 | call to op2 | | result 0 | main.go:53:14:53:21 | call to bump | main.go:53:14:53:21 | call to bump | +| result 0 | main.go:54:10:54:15 | call to test | main.go:54:2:54:2 | definition of x | +| result 0 | main.go:56:9:56:15 | call to test2 | main.go:56:2:56:2 | definition of x | | result 0 | tst2.go:10:9:10:26 | call to NewEncoder | tst2.go:10:9:10:26 | call to NewEncoder | +| result 0 | tst2.go:10:9:10:39 | call to Encode | tst2.go:10:2:10:4 | definition of err | | result 0 | tst.go:9:17:9:33 | call to new | tst.go:9:2:9:12 | definition of bytesBuffer | +| result 1 | main.go:54:10:54:15 | call to test | main.go:54:5:54:5 | definition of y | +| result 1 | main.go:56:9:56:15 | call to test2 | main.go:56:5:56:5 | definition of y |