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

pacslab/DockerMV: go/src/github.com/docker/docker/distribution/push_v2.go; 88 LoC

Aperta
#8,653 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
fresh medium
Lingua principale
Nessun dato sulla lingua
Stelle
0
Fork
0
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Found a possible issue in [pacslab/DockerMV](https://www.github.com/pacslab/DockerMV) at [go/src/github.com/docker/docker/distribution/push_v2.go](https://github.com/pacslab/DockerMV/blob/06c03df00b59a415804baa8746aa1690d0e52f5b/go/src/github.com/docker/docker/distribution/push_v2.go#L314-L401)

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 386 may start a goroutine

[Click here to see the code in its original context.](https://github.com/pacslab/DockerMV/blob/06c03df00b59a415804baa8746aa1690d0e52f5b/go/src/github.com/docker/docker/distribution/push_v2.go#L314-L401)

Click here to show the 88 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.ParseNormalizedNamed(mountCandidate.SourceRepository)
if err != nil {
logrus.Errorf("failed to parse source repository reference %v: %v", reference.FamiliarString(namedRef), err)
pd.v2MetadataService.Remove(mountCandidate)
continue
}

// Candidates are always under same domain, create remote reference
// with only path to set mount from with
remoteRef, err := reference.WithName(reference.Path(namedRef))
if err != nil {
logrus.Errorf("failed to make remote reference out of %q: %v", reference.Path(namedRef), err)
continue
}

canonicalRef, err := reference.WithDigest(reference.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.Name(),
}); err != nil {
return distribution.Descriptor{}, xfer.DoNotRetry{Err: err}
}
return err.Descriptor, nil
case errcode.Errors:
for _, e := range err {
switch e := e.(type) {
case errcode.Error:
if e.Code == errcode.ErrorCodeUnauthorized {
// when unauthorized error that indicate user don't has right to push layer to register
logrus.Debugln("failed to push layer to registry because unauthorized error")
isUnauthorizedError = true
}
default:
}
}
default:
logrus.Infof("failed to mount layer %s (%s) from %s: %v", diffID, mountCandidate.Digest, mountCandidate.SourceRepository, err)
}

// when error is unauthorizedError and user don't hasAuthInfo that's the case user don't has right to push layer to register
// and he hasn't login either, in this case candidate cache should be removed
if len(mountCandidate.SourceRepository) > 0 &&
!(isUnauthorizedError && !pd.pushState.hasAuthInfo) &&
(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 {
"(Update, 1)" -> {"(Update, 2)";}
"(newSerfQueries, 4)" -> {}
"(run, 3)" -> {"(start, 2)";}
"(configureTransport, 1)" -> {"(addConnIfNeeded, 3)";}
"(WatchFrom, 3)" -> {}
"(loadListeners, 2)" -> {"(Init, 4)";}
"(DelayStart, 6)" -> {}
"(awaitOpenSlotForRequest, 1)" -> {}
"(monitorConnection, 1)" -> {}
"(Subscribe, 2)" -> {}
"(Do, 1)" -> {"(Prepare, 2)";"(Put, 1)";}
"(Do, 2)" -> {"(do, 2)";"(RoundTrip, 1)";}
"(do, 2)" -> {}
"(NewNetTransport, 1)" -> {}
"(newTaskManager, 3)" -> {"(newTaskManager, 4)";}
"(Exec, 4)" -> {"(Exec, 2)";}
"(Create, 1)" -> {"(newMemberlist, 1)";"(newSerfQueries, 4)";"(NewSnapshotter, 8)";}
"(reconcileTaskState, 4)" -> {}
"(start, 1)" -> {"(NewDaemon, 4)";"(shutdownDaemon, 1)";"(handleControlSocketChange, 2)";"(loadListeners, 2)";"(ContainerStart, 4)";"(Exec, 4)";}
"(Run, 2)" -> {"(serve, 3)";"(worker, 3)";}
"(Remove, 2)" -> {}
"(initializeSubsystem, 3)" -> {"(Create, 2)";}
"(RoundTrip, 1)" -> {"(start, 1)";"(roundTrip, 1)";"(RoundTripOpt, 2)";}
"(ViewAndWatch, 3)" -> {"(Watch, 2)";}
"(ContainerStart, 4)" -> {"(containerStart, 4)";}
"(updateTask, 4)" -> {"(DelayStart, 6)";}
"(New, 1)" -> {"(run, 1)";"(get, 1)";}
"(Add, 1)" -> {"(New, 1)";"(Delete, 1)";"(Add, 2)";}
"(run, 1)" -> {"(UpdateRootCA, 1)";"(superviseManager, 5)";"(runAgent, 4)";"(Start, 1)";"(newSession, 5)";"(Subscribe, 2)";"(UpdateTaskStatus, 3)";"(Do, 3)";}
"(newSession, 5)" -> {"(run, 3)";}
"(CopyConsole, 7)" -> {}
"(Update, 2)" -> {"(reconcileTaskState, 4)";"(Create, 2)";"(get, 1)";}
"(copyPipes, 7)" -> {}
"(Prepare, 1)" -> {"(Upgrade, 7)";"(Pull, 8)";}
"(SetTransportDefaults, 1)" -> {"(ConfigureTransport, 1)";}
"(Run, 1)" -> {"(WaitForCluster, 2)";"(UpdateNode, 1)";"(run, 3)";"(ViewAndWatch, 3)";}
"(Solve, 4)" -> {"(Run, 2)";}
"(worker, 3)" -> {"(updateTask, 4)";"(useExistingTask, 3)";}
"(runManager, 5)" -> {}
"(NewDaemon, 4)" -> {}
"(handleControlSocketChange, 2)" -> {}
"(LoadPlugins, 1)" -> {"(Init, 1)";}
"(Update, 3)" -> {"(Update, 2)";"(runOrError, 1)";"(Do, 2)";"(Set, 4)";}
"(Join, 2)" -> {"(doRequest, 1)";}
"(Log, 1)" -> {"(Add, 2)";}
"(Init, 1)" -> {"(startTask, 3)";}
"(serve, 3)" -> {}
"(New, 2)" -> {"(newClient, 5)";"(Join, 2)";"(initializeSubsystem, 3)";"(loadCredentials, 1)";"(Add, 1)";"(Update, 1)";"(apply, 2)";"(Register, 1)";"(Init, 1)";"(LoadPlugins, 1)";"(New, 1)";"(Put, 2)";}
"(Register, 1)" -> {"(Put, 3)";"(Add, 2)";}
"(newMemberlist, 1)" -> {"(NewNetTransport, 1)";}
"(Prepare, 2)" -> {"(Prepare, 1)";}
"(startTask, 3)" -> {"(taskManager, 3)";}
"(newTaskManager, 4)" -> {}
"(UpdateNode, 1)" -> {"(aliveNode, 3)";}
"(updateHealthMonitor, 1)" -> {"(monitor, 4)";}
"(loadCredentials, 1)" -> {"(New, 1)";}
"(UpdateRootCA, 1)" -> {}
"(doRequest, 1)" -> {"(SendRequest, 3)";}
"(New, 9)" -> {"(CopyConsole, 7)";"(copyPipes, 7)";}
"(Pull, 8)" -> {"(pull, 4)";}
"(roundTrip, 1)" -> {"(awaitOpenSlotForRequest, 1)";}
"(Init, 4)" -> {"(ListenPipe, 2)";}
"(monitor, 4)" -> {}
"(CheckV2MetadataHMAC, 2)" -> {"(Write, 1)";"(New, 2)";}
"(apply, 2)" -> {"(New, 3)";}
"(runOrError, 1)" -> {"(Start, 1)";}
"(Set, 4)" -> {"(Do, 2)";}
"(aliveNode, 3)" -> {"(NotifyConflict, 2)";}
"(useExistingTask, 3)" -> {"(DelayStart, 6)";}
"(taskManager, 3)" -> {"(newTaskManager, 3)";}
"(Put, 2)" -> {"(New, 1)";}
"(newClient, 5)" -> {"(New, 3)";}
"(runAgent, 4)" -> {}
"(NewSnapshotter, 8)" -> {}
"(Add, 2)" -> {"(Do, 2)";}
"(Set, 2)" -> {"(Add, 2)";}
"(ConfigureTransport, 1)" -> {"(configureTransport, 1)";}
"(RoundTripOpt, 2)" -> {"(roundTrip, 1)";}
"(WaitForCluster, 2)" -> {"(Watch, 2)";}
"(ListenPipe, 2)" -> {}
"(Start, 1)" -> {"(start, 1)";"(CopyConsole, 7)";"(copyPipes, 7)";"(Run, 1)";}
"(Do, 3)" -> {"(Prepare, 1)";}
"(shutdownDaemon, 1)" -> {}
"(Write, 1)" -> {"(Log, 1)";"(New, 1)";"(Put, 1)";"(Do, 1)";"(Update, 3)";"(Set, 2)";}
"(Delete, 1)" -> {"(Remove, 2)";}
"(Put, 3)" -> {"(Create, 1)";}
"(Create, 2)" -> {"(New, 9)";"(Do, 2)";}
"(get, 1)" -> {"(SetTransportDefaults, 1)";}
"(Solve, 2)" -> {"(Solve, 4)";}
"(UpdateTaskStatus, 3)" -> {}
"(superviseManager, 5)" -> {"(runManager, 5)";}
"(start, 2)" -> {}
"(NotifyConflict, 2)" -> {"(handleNodeConflict, 2)";}
"(containerStart, 4)" -> {"(initHealthMonitor, 1)";}
"(handleNodeConflict, 2)" -> {}
"(Put, 1)" -> {"(Create, 1)";"(get, 1)";}
"(New, 3)" -> {"(monitorConnection, 1)";}
"(SendRequest, 3)" -> {"(Do, 3)";}
"(Upgrade, 7)" -> {"(pull, 4)";}
"(pull, 4)" -> {}
"(addConnIfNeeded, 3)" -> {}
"(Watch, 2)" -> {"(WatchFrom, 3)";}
"(initHealthMonitor, 1)" -> {"(updateHealthMonitor, 1)";}
"(Exec, 2)" -> {"(Solve, 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: 06c03df00b59a415804baa8746aa1690d0e52f5b

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Leggi go/src/github.com/docker/docker/distribution/push_v2.go intorno alle righe 314-401, in particolare la chiamata che coinvolge mountCandidate alla riga 386. Traccia se quel riferimento può raggiungere una goroutine, quindi esamina la logica circostante di push e dei metadati; il lavoro è completato quando è stato determinato se il rilevamento dell’analizzatore è un bug, è mitigato o costituisce un comportamento desiderabile, e la classificazione è stata documentata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
go
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
28/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.