github-vet / github-vet/rangeloop-pointer-findings
dts/kubernetes-haproxy-lb: service_loadbalancer.go; 89 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [dts/kubernetes-haproxy-lb](https://www.github.com/dts/kubernetes-haproxy-lb) at [service_loadbalancer.go](https://github.com/dts/kubernetes-haproxy-lb/blob/1bc97b737ee892b5260715c3fdb31b1b983251c3/service_loadbalancer.go#L546-L634)
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 servicePort was used in a composite literal at line 569
[Click here to see the code in its original context.](https://github.com/dts/kubernetes-haproxy-lb/blob/1bc97b737ee892b5260715c3fdb31b1b983251c3/service_loadbalancer.go#L546-L634)
Click here to show the 89 line(s) of Go which triggered the analyzer.
```go
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,
BackendPort: getTargetPort(&servicePort),
}
if priority, ok := serviceAnnotations(s.ObjectMeta.Annotations).getVirtualHostPriority(); ok {
newSvc.Priority = priority
}
if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getVirtualHost(); ok {
newSvc.VirtualHost = val
newSvc.AclSets = calculateAcls(newSvc.Name,val);
}
if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getHost(); ok {
newSvc.Host = 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
}
// By default sslTerm is disabled
newSvc.SslTerm = false
if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getSslTerm(); ok {
b, err := strconv.ParseBool(val)
if err == nil {
newSvc.SslTerm = b
}
}
if val, ok := serviceAnnotations(s.ObjectMeta.Annotations).getAclMatch(); ok {
newSvc.AclMatch = val
}
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
if newSvc.SslTerm == true {
httpsTermSvc = append(httpsTermSvc, newSvc)
} else {
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: 1bc97b737ee892b5260715c3fdb31b1b983251c3
Contributor guide
No contributing guide indexed for this repository
Research direction
Inspect service_loadbalancer.go at lines 546-634, starting with the servicePort range loop and the reported composite literal at line 569. Determine whether the referenced range variable can affect runtime behavior, then classify the finding as Bug, Mitigated, or Desirable Behavior; completion means the classification is supported by the code and its behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100