From 16c4e33b09431fb60dd19bd5eef1b398226172b9 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 30 Jun 2020 11:31:47 +0200 Subject: [PATCH] util: log error when closing temp fail fails in GetOMapValue() gosec-2.3.0 complains about the following: [/go/src/github.com/ceph/ceph-csi/internal/util/cephcmds.go:146] - G307 (CWE-): Deferring unsafe method "*os.File" on type "Close" (Confidence: HIGH, Severity: MEDIUM) > defer tmpFile.Close() By logging the error from Close(), the warning is gone. Signed-off-by: Niels de Vos --- internal/util/cephcmds.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/util/cephcmds.go b/internal/util/cephcmds.go index 7d921df0d..1940aefca 100644 --- a/internal/util/cephcmds.go +++ b/internal/util/cephcmds.go @@ -142,7 +142,12 @@ func GetOMapValue(ctx context.Context, monitors string, cr *Credentials, poolNam klog.Errorf(Log(ctx, "failed creating a temporary file for key contents")) return "", err } - defer tmpFile.Close() + defer func() { + ce := tmpFile.Close() + if ce != nil { + klog.Warningf(Log(ctx, "failed closing temporary file: %s"), ce) + } + }() defer os.Remove(tmpFile.Name()) args := []string{