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

ticketmaster/lbapi: common/create.go; 48 LoC

Open
#10,226 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [ticketmaster/lbapi](https://www.github.com/ticketmaster/lbapi) at [common/create.go](https://github.com/ticketmaster/lbapi/blob/6f8018da1ee0f4afd1353f529baa0c47aa4a8815/common/create.go#L914-L961)

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 d is reassigned at line 919

[Click here to see the code in its original context.](https://github.com/ticketmaster/lbapi/blob/6f8018da1ee0f4afd1353f529baa0c47aa4a8815/common/create.go#L914-L961)

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

```go
for _, d := range dbRecords {
////////////////////////////////////////////////////////////////////////
// Set dbRecord pointer.
////////////////////////////////////////////////////////////////////////
dbRecord := new(DbRecord)
dbRecord = &d
////////////////////////////////////////////////////////////////////////
// Unmarshal Data
////////////////////////////////////////////////////////////////////////
var data Data
shared.MarshalInterface(d.Data, &data)
////////////////////////////////////////////////////////////////////////
if data.ProductCode == 0 {
data.ProductCode = config.GlobalConfig.Lbm.GenericPRD
}
////////////////////////////////////////////////////////////////////////
// Validate Right.
////////////////////////////////////////////////////////////////////////
err = oUser.HasAdminRight(strconv.Itoa(data.ProductCode))
if err != nil {
dbRecord.LastError = err.Error()
r.DbRecords = append(r.DbRecords, *dbRecord)
log.Warn(err)
continue
}
////////////////////////////////////////////////////////////////////////
// Test - Validate payload meets min requirements for submission.
////////////////////////////////////////////////////////////////////////
validated, err := o.Database.Validate(dbRecord)
if err != nil {
dbRecord.LastError = err.Error()
r.DbRecords = append(r.DbRecords, *dbRecord)
log.Warn(err)
continue
}
if !validated {
err = fmt.Errorf("payload did not pass validation - %+v", o.formatData(dbRecord.Data))
dbRecord.LastError = err.Error()
r.DbRecords = append(r.DbRecords, *dbRecord)
log.Warn(err)
continue
}
////////////////////////////////////////////////////////////////////////
// Set DbData.
////////////////////////////////////////////////////////////////////////
qry, id := o.etlDbRecordAdd(dbRecord, &r, oUser)
toDb[id] = qry
}

```

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: 6f8018da1ee0f4afd1353f529baa0c47aa4a8815

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.