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

chef/automate: components/automate-cli/pkg/dev/hab/verify.go; 62 LoC

Open
#13,254 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 [chef/automate](https://www.github.com/chef/automate) at [components/automate-cli/pkg/dev/hab/verify.go](https://github.com/chef/automate/blob/e95960b49bf7a1f2de053c01c278fa792b12c671/components/automate-cli/pkg/dev/hab/verify.go#L201-L262)

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.

> reference to pkg was used in a composite literal at line 205

[Click here to see the code in its original context.](https://github.com/chef/automate/blob/e95960b49bf7a1f2de053c01c278fa792b12c671/components/automate-cli/pkg/dev/hab/verify.go#L201-L262)

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

```go
for _, pkg := range pkgs {
expectedFiles, err := loadFILESFile(pkg)
if err != nil {
errs = append(errs, &VerifyErrBadFileManifest{
pkg: habpkg.Ident(&pkg),
err: err,
})
continue
}
if expectedFiles == nil {
continue
}
presentFiles, err := listFilesInPkg(pkg)
if err != nil {
return err
}

for name := range expectedFiles {
// Some versions of hab put MANIFEST in the
// FILES list and some do not. Because of
// this, listFilesInPkg filters them from
// present files, thus we skip it here too.
//
// See https://github.com/habitat-sh/habitat/issues/6746
//
if filepath.Base(name) == "MANIFEST" {
continue
}

found := false
for _, f := range presentFiles {
if f.filename == name {
found = true
break
}
}
if !found {
errs = append(errs, &VerifyErrMissingFile{
pkg: habpkg.Ident(&pkg),
filename: name,
})
}
}

for _, f := range presentFiles {
if expectedChecksum, ok := expectedFiles[f.filename]; ok {
if expectedChecksum != f.checksum {
errs = append(errs, &VerifyErrChecksumMismatch{
pkg: habpkg.Ident(&pkg),
filename: f.filename,
expectedChecksum: expectedChecksum,
calculatedChecksum: f.checksum,
})
}
} else {
errs = append(errs, &VerifyErrExtraFile{
pkg: habpkg.Ident(&pkg),
filename: f.filename,
})
}
}
}

```

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: e95960b49bf7a1f2de053c01c278fa792b12c671

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.