From a7545cd11b74c754b8988580ecd213e9346ece4b Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Wed, 3 Feb 2021 14:38:53 +0000 Subject: [PATCH] Add test with multiple switch statements --- .../ListOfConstantsSanitizerGuards/test.go | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ql/test/library-tests/semmle/go/dataflow/ListOfConstantsSanitizerGuards/test.go b/ql/test/library-tests/semmle/go/dataflow/ListOfConstantsSanitizerGuards/test.go index 67592a94adc..0f77f4e46df 100644 --- a/ql/test/library-tests/semmle/go/dataflow/ListOfConstantsSanitizerGuards/test.go +++ b/ql/test/library-tests/semmle/go/dataflow/ListOfConstantsSanitizerGuards/test.go @@ -86,6 +86,25 @@ func switchStatementReturningNilOnlyWhenConstant(s string) *string { return &str } +func multipleSwitchStatementReturningTrueOnlyWhenConstant(s string, t string) bool { + switch s { + case constantGlobalVariable, "string literal": + return true + case getRandomString(): + return false + } + switch s { + case "another string literal": + return true + } + switch t { + case "another string literal": + return false + default: + return false + } +} + func switchStatementWithoutUsefulInfo(s string) bool { switch s { case constantGlobalVariable, "string literal": @@ -149,6 +168,15 @@ func main() { } } + { + s := source() + if multipleSwitchStatementReturningTrueOnlyWhenConstant(s, getRandomString()) { + sink(s) + } else { + sink(s) // $dataflow=s + } + } + { s := source() if switchStatementWithoutUsefulInfo(s) {