From ad1cb7e47e9f1c799a0aef819142118afcdf3994 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Fri, 19 Jun 2020 10:28:01 +0200 Subject: [PATCH] Make sure some version information is set when no version was injected into the binary Signed-off-by: Cosmin Cojocar --- cmd/gosec/main.go | 3 +++ cmd/gosec/version.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cmd/gosec/main.go b/cmd/gosec/main.go index 9e05d86659..ad180154de 100644 --- a/cmd/gosec/main.go +++ b/cmd/gosec/main.go @@ -240,6 +240,9 @@ func filterIssues(issues []*gosec.Issue, severity gosec.Score, confidence gosec. } func main() { + // Makes sure some version information is set + prepareVersionInfo() + // Setup usage description flag.Usage = usage diff --git a/cmd/gosec/version.go b/cmd/gosec/version.go index 3ccf679ade..405529c152 100644 --- a/cmd/gosec/version.go +++ b/cmd/gosec/version.go @@ -1,5 +1,9 @@ package main +import ( + "runtime/debug" +) + // Version is the build version var Version string @@ -8,3 +12,14 @@ var GitTag string // BuildDate is the date when the build was created var BuildDate string + +// prepareVersionInfo sets some runtime version when the version value +// was not injected by the build into the binary (e.g. go get). +// This returns currently "(devel)" but not an effective version until +// https://github.com/golang/go/issues/29814 gets resolved. +func prepareVersionInfo() { + if Version == "" { + bi, _ := debug.ReadBuildInfo() + Version = bi.Main.Version + } +}