github-vet / github-vet/rangeloop-pointer-findings

lf-edge/eve: build-tools/src/manifest-tool/vendor/github.com/docker/docker/distribution/push_v2.go; 74 LoC

Open
#8,531 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [lf-edge/eve](https://www.github.com/lf-edge/eve) at [build-tools/src/manifest-tool/vendor/github.com/docker/docker/distribution/push_v2.go](https://github.com/lf-edge/eve/blob/c5aa09586e41a9fd26b2dcff3c242d7c15a430f5/build-tools/src/manifest-tool/vendor/github.com/docker/docker/distribution/push_v2.go#L302-L375)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.

> function call which takes a reference to mountCandidate at line 360 may start a goroutine

[Click here to see the code in its original context.](https://github.com/lf-edge/eve/blob/c5aa09586e41a9fd26b2dcff3c242d7c15a430f5/build-tools/src/manifest-tool/vendor/github.com/docker/docker/distribution/push_v2.go#L302-L375)

Click here to show the 74 line(s) of Go which triggered the analyzer.

```go
for _, mountCandidate := range candidates {
logrus.Debugf("attempting to mount layer %s (%s) from %s", diffID, mountCandidate.Digest, mountCandidate.SourceRepository)
createOpts := []distribution.BlobCreateOption{}

if len(mountCandidate.SourceRepository) > 0 {
namedRef, err := reference.WithName(mountCandidate.SourceRepository)
if err != nil {
logrus.Errorf("failed to parse source repository reference %v: %v", namedRef.String(), err)
pd.v2MetadataService.Remove(mountCandidate)
continue
}

// TODO (brianbland): We need to construct a reference where the Name is
// only the full remote name, so clean this up when distribution has a
// richer reference package
remoteRef, err := distreference.WithName(namedRef.RemoteName())
if err != nil {
logrus.Errorf("failed to make remote reference out of %q: %v", namedRef.RemoteName(), namedRef.RemoteName())
continue
}

canonicalRef, err := distreference.WithDigest(distreference.TrimNamed(remoteRef), mountCandidate.Digest)
if err != nil {
logrus.Errorf("failed to make canonical reference: %v", err)
continue
}

createOpts = append(createOpts, client.WithMountFrom(canonicalRef))
}

// send the layer
lu, err := bs.Create(ctx, createOpts...)
switch err := err.(type) {
case nil:
// noop
case distribution.ErrBlobMounted:
progress.Updatef(progressOutput, pd.ID(), "Mounted from %s", err.From.Name())

err.Descriptor.MediaType = schema2.MediaTypeLayer

pd.pushState.Lock()
pd.pushState.confirmedV2 = true
pd.pushState.remoteLayers[diffID] = err.Descriptor
pd.pushState.Unlock()

// Cache mapping from this layer's DiffID to the blobsum
if err := pd.v2MetadataService.TagAndAdd(diffID, pd.hmacKey, metadata.V2Metadata{
Digest: err.Descriptor.Digest,
SourceRepository: pd.repoInfo.FullName(),
}); err != nil {
return distribution.Descriptor{}, xfer.DoNotRetry{Err: err}
}
return err.Descriptor, nil
default:
logrus.Infof("failed to mount layer %s (%s) from %s: %v", diffID, mountCandidate.Digest, mountCandidate.SourceRepository, err)
}

if len(mountCandidate.SourceRepository) > 0 &&
(metadata.CheckV2MetadataHMAC(&mountCandidate, pd.hmacKey) ||
len(mountCandidate.HMAC) == 0) {
cause := "blob mount failure"
if err != nil {
cause = fmt.Sprintf("an error: %v", err.Error())
}
logrus.Debugf("removing association between layer %s and %s due to %s", mountCandidate.Digest, mountCandidate.SourceRepository, cause)
pd.v2MetadataService.Remove(mountCandidate)
}

if lu != nil {
// cancel previous upload
cancelLayerUpload(ctx, mountCandidate.Digest, layerUpload)
layerUpload = lu
}
}

```

Click here to show extra information the analyzer produced.

```
The following graphviz dot graph describes paths through the callgraph that could lead to a function calling a goroutine:
digraph G {
"(Run, 1)" -> {"(run, 1)";}
"(run, 1)" -> {"(sendICMP, 2)";}
"(sendICMP, 2)" -> {}
"(CheckV2MetadataHMAC, 2)" -> {"(Write, 1)";}
"(Write, 1)" -> {"(Do, 1)";}
"(Do, 1)" -> {"(Upload, 1)";}
"(Upload, 1)" -> {"(GetDataWithRanges, 2)";"(Run, 1)";}
"(GetDataWithRanges, 2)" -> {}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: c5aa09586e41a9fd26b2dcff3c242d7c15a430f5

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.