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

openshift/ci-chat-bot: prow.go; 56 LoC

Open
#15,666 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 [openshift/ci-chat-bot](https://www.github.com/openshift/ci-chat-bot) at [prow.go](https://github.com/openshift/ci-chat-bot/blob/46fb18f0c9412ef72a5bf9b9cf080fd3683cb34d/prow.go#L333-L388)

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 ref was used in a composite literal at line 381

[Click here to see the code in its original context.](https://github.com/openshift/ci-chat-bot/blob/46fb18f0c9412ef72a5bf9b9cf080fd3683cb34d/prow.go#L333-L388)

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

```go
for _, ref := range input.Refs {
configData, ok, err := m.configResolver.Resolve(ref.Org, ref.Repo, ref.BaseRef, "")
if err != nil {
return fmt.Errorf("could not resolve config for %s/%s/%s: %v", ref.Org, ref.Repo, ref.BaseRef, err)
}
if !ok {
return fmt.Errorf("there is no defined configuration for the organization %s with repo %s and branch %s", ref.Org, ref.Repo, ref.BaseRef)
}

var cfg unstructured.Unstructured
if err := yaml.Unmarshal([]byte(configData), &cfg.Object); err != nil {
return fmt.Errorf("unable to parse ci-operator config definition from resolver: %v", err)
}
targetConfig := &cfg
if klog.V(2) {
data, _ := json.MarshalIndent(targetConfig, "", " ")
klog.Infof("Found target job config:\n%s", string(data))
}

// delete sections we don't need
delete(targetConfig.Object, "tests")

if i == 0 && len(job.Inputs) > 1 {
targetConfig.Object["promotion"] = map[string]interface{}{
"name": "stable-initial",
"namespace": "$(NAMESPACE)",
}
targetConfig.Object["tag_specification"] = map[string]interface{}{
"name": "stable-initial",
"namespace": "$(NAMESPACE)",
}
} else {
targetConfig.Object["promotion"] = map[string]interface{}{
"name": "stable",
"namespace": "$(NAMESPACE)",
}
targetConfig.Object["tag_specification"] = map[string]interface{}{
"name": "stable",
"namespace": "$(NAMESPACE)",
}
}

data, err := json.MarshalIndent(targetConfig, "", " ")
if err != nil {
return fmt.Errorf("unable to reformat child job for %#v: %v", ref, err)
}
prow.SetJobEnvVar(&pj.Spec, fmt.Sprintf("CONFIG_SPEC_%d", index), string(data))

data, err = json.MarshalIndent(JobSpec{Refs: &ref}, "", " ")
if err != nil {
return fmt.Errorf("unable to reformat child job for %#v: %v", ref, err)
}
prow.SetJobEnvVar(&pj.Spec, fmt.Sprintf("JOB_SPEC_%d", index), string(data))

index++
}

```

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: 46fb18f0c9412ef72a5bf9b9cf080fd3683cb34d

Contributor guide

No contributing guide indexed for this repository

Research direction

Read prow.go lines 333-388 at commit 46fb18f0c9412ef72a5bf9b9cf080fd3683cb34d, focusing on the input.Refs loop and the JobSpec construction using ref. Check the surrounding project context and Go range-variable behavior, then determine whether the analyzer finding is a bug, mitigated, or desirable behavior and leave the corresponding reaction.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.