github-vet / github-vet/rangeloop-pointer-findings
Ramso-dev/cback: services/admin.go; 60 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [Ramso-dev/cback](https://www.github.com/Ramso-dev/cback) at [services/admin.go](https://github.com/Ramso-dev/cback/blob/1013dd99004046c90e387bc4fa515e75fc80425e/services/admin.go#L580-L639)
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 event is reassigned at line 601
[Click here to see the code in its original context.](https://github.com/Ramso-dev/cback/blob/1013dd99004046c90e387bc4fa515e75fc80425e/services/admin.go#L580-L639)
Click here to show the 60 line(s) of Go which triggered the analyzer.
```go
for _,event := range events{
c := session.DB(AuthDatabase).C(CalendarCollection)
err := c.Insert(event)
if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError)
log.Println("Failed insert 1: ", err)
return
}
c = session.DB(AuthDatabase).C(UserCollection)
var user models.User
err = c.Find(bson.M{"email": event.Email}).One(&user)
if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError)
log.Println("Failed insert 2: ", err)
return
}
user.NextEvent=&event
user.Events=append(user.Events,&event)
err = c.Update(bson.M{"email": event.Email},&user)
if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError)
log.Println("Failed insert 3: ", err)
return
}
c = session.DB(AuthDatabase).C(CalendarCollection)
err = c.Find(bson.M{"email": event.Email}).One(&event)
if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError)
log.Println("Failed insert 4a: ", err)
return
}
event.RelateID=user.Id
log.Println(event)
err = c.Update(bson.M{"email": event.Email},&event)
if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError)
log.Println("Failed insert 4: ", err)
return
}
/*
err = c.Update(bson.M{"email": event.Email}).One(&user)
err := c.Insert(event)
if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError)
log.Println("Failed insert user: ", err)
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: 1013dd99004046c90e387bc4fa515e75fc80425e
Contributor guide
No contributing guide indexed for this repository
Research direction
Read services/admin.go around lines 580-639 in the referenced cback commit, starting with the range loop and the analyzer message about event being reassigned. Check whether the references to event create incorrect behavior, then classify the finding as Bug, Mitigated, or Desirable Behavior by leaving the corresponding reaction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100