From 006f9d321a512e5ecbe7b35a713ac5cb91282b9e Mon Sep 17 00:00:00 2001 From: He Weiwei Date: Wed, 27 May 2020 09:52:01 +0000 Subject: [PATCH] fix(cve-whitelist): fix panic in `Get` method of whitelist manager Closes #11951 Signed-off-by: He Weiwei --- src/pkg/scan/whitelist/manager.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pkg/scan/whitelist/manager.go b/src/pkg/scan/whitelist/manager.go index 2d244bdb2..4ce24144e 100644 --- a/src/pkg/scan/whitelist/manager.go +++ b/src/pkg/scan/whitelist/manager.go @@ -63,14 +63,17 @@ func (d *defaultManager) Set(projectID int64, list models.CVEWhitelist) error { // Get gets the whitelist for given project func (d *defaultManager) Get(projectID int64) (*models.CVEWhitelist, error) { wl, err := dao.GetCVEWhitelist(projectID) - if wl == nil && err == nil { - log.Debugf("No CVE whitelist found for project %d, returning empty list.", projectID) - return &models.CVEWhitelist{ProjectID: projectID, Items: []models.CVEWhitelistItem{}}, nil + if err != nil { + return nil, err } - if wl.Items == nil { + + if wl == nil { + log.Debugf("No CVE whitelist found for project %d, returning empty list.", projectID) + wl = &models.CVEWhitelist{ProjectID: projectID, Items: []models.CVEWhitelistItem{}} + } else if wl.Items == nil { wl.Items = []models.CVEWhitelistItem{} } - return wl, err + return wl, nil } // SetSys sets the system level whitelist