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