Skip to content

Commit

Permalink
fix nil pointer in storing SBOM and CVE
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
  • Loading branch information
matthyx committed Apr 6, 2023
1 parent 96f50f0 commit bff9239
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 11 additions & 7 deletions repositories/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ func (a *APIServerStore) StoreCVE(ctx context.Context, cve domain.CVEManifest, w
DatabaseVersion: cve.CVEDBVersion,
},
},
Payload: *cve.Content,
},
}
if cve.Content != nil {
manifest.Spec.Payload = *cve.Content
}
_, err := a.StorageClient.VulnerabilityManifests(a.Namespace).Create(context.Background(), &manifest, metav1.CreateOptions{})
switch {
case errors.IsAlreadyExists(err):
Expand Down Expand Up @@ -242,19 +244,21 @@ func (a *APIServerStore) StoreSBOM(ctx context.Context, sbom domain.SBOM) error
Version: sbom.SBOMCreatorVersion,
},
},
SPDX: *sbom.Content,
},
Status: v1beta1.SBOMSPDXv2p3Status{}, // TODO move timeout information here
}
if sbom.Content != nil {
manifest.Spec.SPDX = *sbom.Content
created, err := time.Parse(time.RFC3339, sbom.Content.CreationInfo.Created)
if err != nil {
manifest.Spec.Metadata.Report.CreatedAt.Time = created
}
}
if manifest.Annotations == nil {
manifest.Annotations = map[string]string{}
}
manifest.Annotations[instanceidhandler.StatusMetadataKey] = sbom.Status // for the moment stored as an annotation
created, err := time.Parse(time.RFC3339, sbom.Content.CreationInfo.Created)
if err != nil {
manifest.Spec.Metadata.Report.CreatedAt.Time = created
}
_, err = a.StorageClient.SBOMSPDXv2p3s(a.Namespace).Create(context.Background(), &manifest, metav1.CreateOptions{})
_, err := a.StorageClient.SBOMSPDXv2p3s(a.Namespace).Create(context.Background(), &manifest, metav1.CreateOptions{})
switch {
case errors.IsAlreadyExists(err):
logger.L().Debug("SBOM manifest already exists in storage", helpers.String("ID", sbom.ID))
Expand Down
7 changes: 4 additions & 3 deletions repositories/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ func (a *APIServerStore) storeSBOMp(ctx context.Context, sbom domain.SBOM) error
instanceidhandler.StatusMetadataKey: sbom.Status,
},
},
Spec: v1beta1.SBOMSPDXv2p3Spec{
SPDX: *sbom.Content,
},
Spec: v1beta1.SBOMSPDXv2p3Spec{},
}
if sbom.Content != nil {
manifest.Spec.SPDX = *sbom.Content
}
_, err := a.StorageClient.SBOMSPDXv2p3Filtereds(a.Namespace).Create(ctx, &manifest, metav1.CreateOptions{})
return err
Expand Down

0 comments on commit bff9239

Please sign in to comment.