From bd595339a5ef3568aae34b6062315f7cb775a1f6 Mon Sep 17 00:00:00 2001 From: adarsh-dell Date: Tue, 20 Feb 2024 03:03:49 -0500 Subject: [PATCH] Go sec fix --- main.go | 20 ++++++++++++++++---- retriever/go-metadata-retreiver.go | 10 ++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 15a9470..a688d9d 100644 --- a/main.go +++ b/main.go @@ -57,9 +57,18 @@ func Run( if v, ok := csictx.LookupEnv(ctx, gocsi.EnvVarDebug); ok { /* #nosec G104 */ if ok, _ := strconv.ParseBool(v); ok { - csictx.Setenv(ctx, gocsi.EnvVarLogLevel, "debug") - csictx.Setenv(ctx, gocsi.EnvVarReqLogging, "true") - csictx.Setenv(ctx, gocsi.EnvVarRepLogging, "true") + err := csictx.Setenv(ctx, gocsi.EnvVarLogLevel, "debug") + if err != nil { + log.Warnf("failed to set EnvVarLogLevel") + } + err = csictx.Setenv(ctx, gocsi.EnvVarReqLogging, "true") + if err != nil { + log.Warnf("failed to set EnvVarReqLogging") + } + err = csictx.Setenv(ctx, gocsi.EnvVarRepLogging, "true") + if err != nil { + log.Warnf("failed to set EnvVarRepLogging") + } } } @@ -130,7 +139,10 @@ func Run( /* #nosec G104 */ if l.Addr().Network() == netUnix { sockFile := l.Addr().String() - os.RemoveAll(sockFile) + err := os.RemoveAll(sockFile) + if err != nil { + log.Warnf("failed to remove sock file: %s", err) + } log.WithField("path", sockFile).Info("removed sock file") } }) diff --git a/retriever/go-metadata-retreiver.go b/retriever/go-metadata-retreiver.go index 4156df4..72566e2 100644 --- a/retriever/go-metadata-retreiver.go +++ b/retriever/go-metadata-retreiver.go @@ -359,8 +359,14 @@ func (sp *Plugin) initEnvVars(ctx context.Context) { if v, ok := csictx.LookupEnv(ctx, gocsi.EnvVarDebug); ok { /* #nosec G104 */ if ok, _ := strconv.ParseBool(v); ok { - csictx.Setenv(ctx, gocsi.EnvVarReqLogging, "true") - csictx.Setenv(ctx, gocsi.EnvVarRepLogging, "true") + err := csictx.Setenv(ctx, gocsi.EnvVarReqLogging, "true") + if err != nil { + log.Warnf("failed to set EnvVarReqLogging") + } + err = csictx.Setenv(ctx, gocsi.EnvVarRepLogging, "true") + if err != nil { + log.Warnf("failed to set EnvVarRepLogging") + } } }