Merge pull request #2156 from tonistiigi/nil-deref-fix

cache: fix possible nil dereferences
v0.9
Akihiro Suda 2021-06-08 14:26:32 +09:00 committed by GitHub
commit d458fb3043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 5 deletions

14
cache/manager.go vendored
View File

@ -150,11 +150,14 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispec.Descriptor,
return nil, err return nil, err
} }
if len(sis) > 0 { for _, si := range sis {
ref, err := cm.get(ctx, sis[0].ID(), opts...) ref, err := cm.get(ctx, si.ID(), opts...)
if err != nil && !IsNotFound(err) { if err != nil && !IsNotFound(err) {
return nil, errors.Wrapf(err, "failed to get record %s by blobchainid", sis[0].ID()) return nil, errors.Wrapf(err, "failed to get record %s by blobchainid", sis[0].ID())
} }
if ref == nil {
continue
}
if p != nil { if p != nil {
releaseParent = true releaseParent = true
} }
@ -170,12 +173,15 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispec.Descriptor,
} }
var link ImmutableRef var link ImmutableRef
if len(sis) > 0 { for _, si := range sis {
ref, err := cm.get(ctx, sis[0].ID(), opts...) ref, err := cm.get(ctx, si.ID(), opts...)
if err != nil && !IsNotFound(err) { if err != nil && !IsNotFound(err) {
return nil, errors.Wrapf(err, "failed to get record %s by chainid", sis[0].ID()) return nil, errors.Wrapf(err, "failed to get record %s by chainid", sis[0].ID())
} }
if ref != nil {
link = ref link = ref
break
}
} }
id := identity.NewID() id := identity.NewID()