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

LF-Engineering/dev-analytics-affiliation: shdb/service.go; 160 LoC

Open
#18,385 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 [LF-Engineering/dev-analytics-affiliation](https://www.github.com/LF-Engineering/dev-analytics-affiliation) at [shdb/service.go](https://github.com/LF-Engineering/dev-analytics-affiliation/blob/62e88c96449d1f30a0015cb3c47ac711bc386561/shdb/service.go#L7899-L8058)

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

[Click here to see the code in its original context.](https://github.com/LF-Engineering/dev-analytics-affiliation/blob/62e88c96449d1f30a0015cb3c47ac711bc386561/shdb/service.go#L7899-L8058)

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

```go
for uuid := range uuids {
var genderAcc *int64
if prof.Gender != nil {
i100 := int64(100)
genderAcc = &i100
}
profile := &models.ProfileDataOutput{
UUID: uuid,
Name: prof.Name,
Email: prof.Email,
Gender: prof.Gender,
GenderAcc: genderAcc,
IsBot: prof.IsBot,
CountryCode: prof.CountryCode,
}
_, err = s.EditProfile(profile, false, tx)
if err != nil {
return
}
for _, iden := range delProf.Identities {
columns := []string{"uuid", "source"}
values := []interface{}{uuid, iden.Source}
isDates := []bool{false, false}
if iden.Name != nil {
columns = append(columns, "name")
values = append(values, *iden.Name)
isDates = append(isDates, false)
}
if iden.Email != nil {
columns = append(columns, "email")
values = append(values, *iden.Email)
isDates = append(isDates, false)
}
if iden.Username != nil {
columns = append(columns, "username")
values = append(values, *iden.Username)
isDates = append(isDates, false)
}
var identities []*models.IdentityDataOutput
identities, err = s.FindIdentities(columns, values, isDates, false, tx)
if err != nil {
return
}
for _, identity := range identities {
err = s.DeleteIdentity(identity.ID, false, false, nil, tx)
if err != nil {
return
}
}
}
for _, rol := range delProf.Enrollments {
var (
start time.Time
end time.Time
organization *models.OrganizationDataOutput
enrollments []*models.EnrollmentDataOutput
ok bool
)
start, err = s.TimeParseAny(rol.Start)
if err != nil {
return
}
end, err = s.TimeParseAny(rol.End)
if err != nil {
return
}
organization, ok = mOrgName[rol.Organization]
if !ok {
organization, err = s.GetOrganizationByName(rol.Organization, true, tx)
if err != nil {
return
}
mOrgName[rol.Organization] = organization
mOrgID[organization.ID] = organization
}
enrollments, err = s.FindEnrollments(
[]string{"uuid", "start", "end", "organization_id", "project_slug", "role"},
[]interface{}{
uuid,
strfmt.DateTime(start),
strfmt.DateTime(end),
organization.ID,
rol.ProjectSlug,
rol.Role,
},
[]bool{false, true, true, false, false, false},
false,
tx,
)
if err != nil {
return
}
for _, enrollment := range enrollments {
err = s.DeleteEnrollment(enrollment.ID, false, false, nil, tx)
if err != nil {
return
}
}
}
for _, iden := range prof.Identities {
identity := &models.IdentityDataOutput{
UUID: &uuid,
Source: iden.Source,
Email: iden.Email,
Name: iden.Name,
Username: iden.Username,
}
iid := ""
iid, err = s.IdentityIDHash(identity)
if err != nil {
return
}
identity.ID = iid
iobj := &shared.LocalIdentityShortOutput{IdentityShortOutput: iden}
log.Info(fmt.Sprintf("BulkUpdate: update profile identity '%s' - generated identity ID '%s'", iobj.SortKey(), iid))
_, err = s.AddIdentity(identity, true, false, tx)
if err != nil {
return
}
}
var (
start time.Time
end time.Time
)
for _, rol := range prof.Enrollments {
start, err = s.TimeParseAny(rol.Start)
if err != nil {
return
}
end, err = s.TimeParseAny(rol.End)
if err != nil {
return
}
var (
organization *models.OrganizationDataOutput
ok bool
)
organization, ok = mOrgName[rol.Organization]
if !ok {
organization, err = s.GetOrganizationByName(rol.Organization, true, tx)
if err != nil {
return
}
mOrgName[rol.Organization] = organization
mOrgID[organization.ID] = organization
}
enrollment := &models.EnrollmentDataOutput{
UUID: uuid,
Start: strfmt.DateTime(start),
End: strfmt.DateTime(end),
OrganizationID: organization.ID,
ProjectSlug: rol.ProjectSlug,
Role: rol.Role,
}
_, err = s.AddEnrollment(enrollment, true, false, tx)
if err != nil {
return
}
}
}

```

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: 62e88c96449d1f30a0015cb3c47ac711bc386561

Contributor guide

No contributing guide indexed for this repository

Research direction

The finding is in shdb/service.go, lines 7899-8058, within the BulkUpdate flow. Start by reading the surrounding range loop and the IdentityDataOutput construction that takes &uuid, then determine whether that reference can produce incorrect identity data. Done means deciding whether the analyzer finding is a bug, mitigated, or desirable behavior and leaving the requested reaction.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.