-
Notifications
You must be signed in to change notification settings - Fork 259
Description
What steps did you take and what happened:
I've been analyzing the source code using the Svace static analyzer and it has found some inconsistent error-checking issues that I believe are confirmed.
What did you expect to happen:
Redundant error checks are removed and incorrect ones are adjusted
Anything else you would like to add:
The err variable is double-checked:
(consider removing the second check)
trivy-operator/pkg/plugins/trivy/filesystem.go
Lines 214 to 221 in 1caa4d4
config, err := getConfig(ctx) if err != nil { return corev1.PodSpec{}, nil, err } command := config.GetCommand() if err != nil { return corev1.PodSpec{}, nil, err } trivy-operator/pkg/plugins/trivy/filesystem.go
Lines 444 to 451 in 1caa4d4
config, err := getConfig(ctx) if err != nil { return corev1.PodSpec{}, nil, err } command := config.GetCommand() if err != nil { return corev1.PodSpec{}, nil, err } trivy-operator/pkg/plugins/trivy/plugin.go
Lines 135 to 142 in 1caa4d4
config, err := getConfig(ctx) if err != nil { return vulnReport, secretReport, nil, err } cmd := config.GetCommand() if err != nil { // TODO: condition seems incorrect return vulnReport, secretReport, nil, err }
Incorrect check of the ok variable:
(also I guess trivyoperator.LabelResourceSpecHash should be trivyoperator.LabelReusedReport in the error message)
trivy-operator/pkg/vulnerabilityreport/controller/scanjob.go
Lines 313 to 316 in 1caa4d4
_, reused := job.Labels[trivyoperator.LabelReusedReport] if !ok { return VulnerabilityReports{}, nil, nil, fmt.Errorf("expected label %s not set", trivyoperator.LabelResourceSpecHash) }
which is obtained from:
trivy-operator/pkg/vulnerabilityreport/controller/scanjob.go
Lines 259 to 262 in 1caa4d4
| podSpecHash, ok := job.Labels[trivyoperator.LabelResourceSpecHash] | |
| if !ok { | |
| return VulnerabilityReports{}, nil, nil, fmt.Errorf("expected label %s not set", trivyoperator.LabelResourceSpecHash) | |
| } |
So I believe the fix would be:
reused, ok := job.Labels[trivyoperator.LabelReusedReport]
if !ok {
return VulnerabilityReports{}, nil, nil, fmt.Errorf("expected label %s not set", trivyoperator.LabelReusedReport)
} Environment:
- Trivy-Operator version (use
trivy-operator version):v0.27.3(also checked that problem persists inmainbranch)
Found by Linux Verification Center with SVACE