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

HorizonXP/kubernetes-haproxy: service_loadbalancer.go; 72 LoC

Open
#14,174 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 [HorizonXP/kubernetes-haproxy](https://www.github.com/HorizonXP/kubernetes-haproxy) at [service_loadbalancer.go](https://github.com/HorizonXP/kubernetes-haproxy/blob/c7aef80c1d32fa130cd4da304db0f8ef96b56a50/service_loadbalancer.go#L405-L476)

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

[Click here to see the code in its original context.](https://github.com/HorizonXP/kubernetes-haproxy/blob/c7aef80c1d32fa130cd4da304db0f8ef96b56a50/service_loadbalancer.go#L405-L476)

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

```go
for _, s := range services.Items {
if s.Spec.Type == api.ServiceTypeLoadBalancer {
glog.Infof("Ignoring service %v, it already has a loadbalancer", s.Name)
continue
}
for _, servicePort := range s.Spec.Ports {
// TODO: headless services?
sName := s.Name
if servicePort.Protocol == api.ProtocolUDP ||
(lbc.targetService != "" && lbc.targetService != sName) {
glog.Infof("Ignoring %v: %+v", sName, servicePort)
continue
}

if lbc.forwardServices {
ep = []string{
fmt.Sprintf("%v:%v", s.Spec.ClusterIP, servicePort.Port)}
} else {
ep = lbc.getEndpoints(&s, &servicePort)
}
if len(ep) == 0 {
glog.Infof("No endpoints found for service %v, port %+v",
sName, servicePort)
continue
}
newSvc := service{
Name: getServiceNameForLBRule(&s, servicePort.Port),
Ep: ep,
}

if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getHost(); ok {
newSvc.Host = val
}

if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getSSLCert(); ok {
newSvc.SSLCert = val
}

if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getAlgorithm(); ok {
for _, current := range supportedAlgorithms {
if val == current {
newSvc.Algorithm = val
break
}
}
} else {
newSvc.Algorithm = lbc.cfg.lbDefAlgorithm
}

// By default sticky session is disabled
newSvc.SessionAffinity = false
if s.Spec.SessionAffinity != "" {
newSvc.SessionAffinity = true
}

if port, ok := lbc.tcpServices[sName]; ok && port == servicePort.Port {
newSvc.FrontendPort = servicePort.Port
tcpSvc = append(tcpSvc, newSvc)
} else {
if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getCookieStickySession(); ok {
b, err := strconv.ParseBool(val)
if err == nil {
newSvc.CookieStickySession = b
}
}

newSvc.FrontendPort = lbc.httpPort
httpSvc = append(httpSvc, newSvc)
}
glog.Infof("Found service: %+v", newSvc)
}
}

```

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with service_loadbalancer.go lines 405-476 and read the surrounding uses of the range variable s. Check whether the references passed to getEndpoints and getServiceNameForLBRule can outlive the loop iteration, then compare the finding with the repository's classification guidance. Done means leaving a reaction classifying it as Bug, Mitigated, or Desirable Behavior.

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
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.