github-vet / github-vet/rangeloop-pointer-findings
hashicorp/packer: builder/tencentcloud/cvm/artifact.go; 63 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [hashicorp/packer](https://www.github.com/hashicorp/packer) at [builder/tencentcloud/cvm/artifact.go](https://github.com/hashicorp/packer/blob/28245ec1434dbbcde312633b4dd9c46a800f306d/builder/tencentcloud/cvm/artifact.go#L69-L131)
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 imageId is reassigned at line 92
[Click here to see the code in its original context.](https://github.com/hashicorp/packer/blob/28245ec1434dbbcde312633b4dd9c46a800f306d/builder/tencentcloud/cvm/artifact.go#L69-L131)
Click here to show the 63 line(s) of Go which triggered the analyzer.
```go
for region, imageId := range a.TencentCloudImages {
log.Printf("Delete tencentcloud image ID(%s) from region(%s)", imageId, region)
describeReq := cvm.NewDescribeImagesRequest()
describeReq.ImageIds = []*string{&imageId}
var describeResp *cvm.DescribeImagesResponse
err := Retry(ctx, func(ctx context.Context) error {
var e error
describeResp, e = a.Client.DescribeImages(describeReq)
return e
})
if err != nil {
errors = append(errors, err)
continue
}
if *describeResp.Response.TotalCount == 0 {
errors = append(errors, fmt.Errorf(
"describe images failed, region(%s) ImageId(%s)", region, imageId))
}
var shareAccountIds []*string = nil
describeShareReq := cvm.NewDescribeImageSharePermissionRequest()
describeShareReq.ImageId = &imageId
var describeShareResp *cvm.DescribeImageSharePermissionResponse
err = Retry(ctx, func(ctx context.Context) error {
var e error
describeShareResp, e = a.Client.DescribeImageSharePermission(describeShareReq)
return e
})
if err != nil {
errors = append(errors, err)
} else {
for _, sharePermission := range describeShareResp.Response.SharePermissionSet {
shareAccountIds = append(shareAccountIds, sharePermission.AccountId)
}
}
if len(shareAccountIds) != 0 {
cancelShareReq := cvm.NewModifyImageSharePermissionRequest()
cancelShareReq.ImageId = &imageId
cancelShareReq.AccountIds = shareAccountIds
CANCEL := "CANCEL"
cancelShareReq.Permission = &CANCEL
err := Retry(ctx, func(ctx context.Context) error {
_, e := a.Client.ModifyImageSharePermission(cancelShareReq)
return e
})
if err != nil {
errors = append(errors, err)
}
}
deleteReq := cvm.NewDeleteImagesRequest()
deleteReq.ImageIds = []*string{&imageId}
err = Retry(ctx, func(ctx context.Context) error {
_, e := a.Client.DeleteImages(deleteReq)
return e
})
if err != nil {
errors = append(errors, err)
}
}
```
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: 28245ec1434dbbcde312633b4dd9c46a800f306d
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.