From b623a4c8ec0fb0477b6243c6fc6af9062f56c8d1 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Wed, 20 Jan 2021 14:35:45 +0000 Subject: [PATCH] Add tests for guarding functions proxied by a variable Negation doesn't appear to be handled correctly, so one of the lines is marked as a false positive. --- .../go/dataflow/GuardingFunctions/test.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ql/test/library-tests/semmle/go/dataflow/GuardingFunctions/test.go b/ql/test/library-tests/semmle/go/dataflow/GuardingFunctions/test.go index 729c9518e55..4924d0e79be 100644 --- a/ql/test/library-tests/semmle/go/dataflow/GuardingFunctions/test.go +++ b/ql/test/library-tests/semmle/go/dataflow/GuardingFunctions/test.go @@ -825,4 +825,27 @@ func test() { } } + // Note we can also assign the result of a guarding function to a variable and use that in + // the conditional. + + { + s := source() + isInvalid := guardBool(s) + if isInvalid { + sink(s) // $dataflow=s + } else { + sink(s) + } + } + + { + s := source() + isValid := !guardBool(s) + if isValid { + sink(s) // $f+:dataflow=s + } else { + sink(s) // $dataflow=s + } + } + }