From 3188e3fb8ededa023e7e76a25ceaa45a2a3d5828 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Fri, 10 Nov 2023 10:28:38 +0100 Subject: [PATCH] Ensure ignores are handled properly for multi-line issues Signed-off-by: Cosmin Cojocar --- analyzer.go | 2 +- testutils/source.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/analyzer.go b/analyzer.go index bcb9143729..304f4a2518 100644 --- a/analyzer.go +++ b/analyzer.go @@ -123,7 +123,7 @@ func (i ignores) get(file string, line string) map[string][]issue.SuppressionInf start, end := i.parseLine(line) if is, ok := i[file]; ok { for _, i := range is { - if i.start <= start && i.end >= end { + if start <= i.start && end >= i.end { return i.suppressions } } diff --git a/testutils/source.go b/testutils/source.go index c5a5713680..2bb03e7efc 100644 --- a/testutils/source.go +++ b/testutils/source.go @@ -1214,6 +1214,38 @@ func HelloServer(w http.ResponseWriter, r *http.Request) { } } `}, 0, gosec.NewConfig()}, + {[]string{` + package main + + import ( + "fmt" + "net/http" + "sync" + ) + + type Server struct { + hs *http.Server + mux *http.ServeMux + mu sync.Mutex + } + + func New(listenAddr string) *Server { + mux := http.NewServeMux() + + return &Server{ + hs: &http.Server{ // #nosec G112 - Not publicly exposed + Addr: listenAddr, + Handler: mux, + }, + mux: mux, + mu: sync.Mutex{}, + } + } + + func main() { + fmt.Print("test") + } + `}, 0, gosec.NewConfig()}, } // SampleCodeG113 - Usage of Rat.SetString in math/big with an overflow