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

triansetyabudi/sambelenak: gateway/middleware.go; 120 LoC

Open
#14,841 0 comments 0 reactions 0 assignees View on GitHub
fresh large
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [triansetyabudi/sambelenak](https://www.github.com/triansetyabudi/sambelenak) at [gateway/middleware.go](https://github.com/triansetyabudi/sambelenak/blob/1d01aad5940891a85c9205b8a667abce1c292dd1/gateway/middleware.go#L378-L497)

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 v is reassigned at line 379

[Click here to see the code in its original context.](https://github.com/triansetyabudi/sambelenak/blob/1d01aad5940891a85c9205b8a667abce1c292dd1/gateway/middleware.go#L378-L497)

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

```go
for k, v := range policy.AccessRights {
ar := &v

if v.Limit == nil {
v.Limit = &user.APILimit{}
}

if !usePartitions || policy.Partitions.Acl {
didACL[k] = true

// Merge ACLs for the same API
if r, ok := rights[k]; ok {
r.Versions = appendIfMissing(rights[k].Versions, v.Versions...)

for _, u := range v.AllowedURLs {
found := false
for ai, au := range r.AllowedURLs {
if u.URL == au.URL {
found = true
r.AllowedURLs[ai].Methods = append(au.Methods, u.Methods...)
}
}

if !found {
r.AllowedURLs = append(r.AllowedURLs, v.AllowedURLs...)
}
}

for _, t := range v.RestrictedTypes {
found := false
for ri, rt := range r.RestrictedTypes {
if t.Name == rt.Name {
found = true
r.RestrictedTypes[ri].Fields = append(rt.Fields, t.Fields...)
}
}

if !found {
r.RestrictedTypes = append(r.RestrictedTypes, v.RestrictedTypes...)
}
}

ar = &r
}

ar.Limit.SetBy = policy.ID
}

if !usePartitions || policy.Partitions.Quota {
didQuota[k] = true
if greaterThanInt64(policy.QuotaMax, ar.Limit.QuotaMax) {

ar.Limit.QuotaMax = policy.QuotaMax
//if partition for quota is set the we must use this value in the global information of the key
if greaterThanInt64(policy.QuotaMax, session.QuotaMax) || policy.Partitions.Quota {
session.QuotaMax = policy.QuotaMax
}
}

if policy.QuotaRenewalRate > ar.Limit.QuotaRenewalRate {
ar.Limit.QuotaRenewalRate = policy.QuotaRenewalRate
if policy.QuotaRenewalRate > session.QuotaRenewalRate {
session.QuotaRenewalRate = policy.QuotaRenewalRate
}
}
}

if !usePartitions || policy.Partitions.RateLimit {
didRateLimit[k] = true

if greaterThanFloat64(policy.Rate, ar.Limit.Rate) {
ar.Limit.Rate = policy.Rate
//if policy.Partitions.RateLimit then we must set this value in the global data of the key
if greaterThanFloat64(policy.Rate, session.Rate) || policy.Partitions.RateLimit {
session.Rate = policy.Rate
}
}

if policy.Per > ar.Limit.Per {
ar.Limit.Per = policy.Per
if policy.Per > session.Per {
session.Per = policy.Per
}
}

if policy.ThrottleRetryLimit > ar.Limit.ThrottleRetryLimit {
ar.Limit.ThrottleRetryLimit = policy.ThrottleRetryLimit
if policy.ThrottleRetryLimit > session.ThrottleRetryLimit {
session.ThrottleRetryLimit = policy.ThrottleRetryLimit
}
}

if policy.ThrottleInterval > ar.Limit.ThrottleInterval {
ar.Limit.ThrottleInterval = policy.ThrottleInterval
if policy.ThrottleInterval > session.ThrottleInterval {
session.ThrottleInterval = policy.ThrottleInterval
}
}
}

if !usePartitions || policy.Partitions.Complexity {
didComplexity[k] = true

if greaterThanInt(policy.MaxQueryDepth, ar.Limit.MaxQueryDepth) {
ar.Limit.MaxQueryDepth = policy.MaxQueryDepth
if greaterThanInt(policy.MaxQueryDepth, session.MaxQueryDepth) {
session.MaxQueryDepth = policy.MaxQueryDepth
}
}
}

// Respect existing QuotaRenews
if r, ok := session.AccessRights[k]; ok && r.Limit != nil {
ar.Limit.QuotaRenews = r.Limit.QuotaRenews
}

if !usePartitions || policy.Partitions.Acl {
rights[k] = *ar
}
}

```

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: 1d01aad5940891a85c9205b8a667abce1c292dd1

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.