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

sagap/Peerster: hw3/part2/gossiper2_backend/gossiper2.go; 22 LoC

Open
#11,584 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 [sagap/Peerster](https://www.github.com/sagap/Peerster) at [hw3/part2/gossiper2_backend/gossiper2.go](https://github.com/sagap/Peerster/blob/8b4ac1aec5674313c070f74dd8ae3f38c456b94e/hw3/part2/gossiper2_backend/gossiper2.go#L370-L391)

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

[Click here to see the code in its original context.](https://github.com/sagap/Peerster/blob/8b4ac1aec5674313c070f74dd8ae3f38c456b94e/hw3/part2/gossiper2_backend/gossiper2.go#L370-L391)

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

```go
for msg := range gossiper.msgChnPriv {
if strings.Compare(msg.Text, "") == 0 || strings.Compare(msg.Dest, "") == 0 { // in case someone does not include Dest or Test
return
}
if strings.Compare(msg.Origin, "") == 0 {
msg.Origin = gossiper.origin
}
if strings.Compare(msg.Dest, gossiper.origin) == 0 {
fmt.Print("PRIVATE: ", msg.Origin, ":", msg.HopLimit, ":", msg.Text, "\n")
gossiper.mupriv.Lock()
gossiper.privateList[time.Now()] = msg
gossiper.mupriv.Unlock()
} else {
msg.HopLimit--
if msg.HopLimit == 0 {
return
} else {
messageToSend := messaging.GossipPacket{nil, nil, &msg, nil, nil,nil,nil,nil}
go gossiper.sendPrivateMessages(messageToSend, msg.Dest)
}
}
}

```

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: 8b4ac1aec5674313c070f74dd8ae3f38c456b94e

Contributor guide

No contributing guide indexed for this repository

Research direction

Read hw3/part2/gossiper2_backend/gossiper2.go around lines 370-391 and inspect the analyzer warning about the reference to msg. Trace the private-message forwarding path through sendPrivateMessages, then verify that the warning is resolved without changing the intended message behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.