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

HaoKunT/HKComm: hkcmd/HKComm/community.go; 53 LoC

Open
#12,874 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [HaoKunT/HKComm](https://www.github.com/HaoKunT/HKComm) at [hkcmd/HKComm/community.go](https://github.com/HaoKunT/HKComm/blob/d40d12247406459987090dff2000f973444e5079/hkcmd/HKComm/community.go#L172-L224)

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 msgIn is reassigned at line 209

[Click here to see the code in its original context.](https://github.com/HaoKunT/HKComm/blob/d40d12247406459987090dff2000f973444e5079/hkcmd/HKComm/community.go#L172-L224)

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

```go
for msgIn := range msgInCh {
// 根据connection获取发送者ID,与包不符合则丢弃
if msgIn.connection.senderID != msgIn.From {
checkError(fmt.Errorf("connection sender (id:%d) mismatch the sender (id:%d)", msgIn.connection.senderID, msgIn.From))
continue
}
// 给消息附上唯一的ID
msgIn.generateID()
// 判断是否有这个成员,避免出现精心构造好的包
_, err := msgIn.GetSender(false)
if checkError(err) != nil {
continue
}
// 如果是群消息
if msgIn.Isgroup {
// 首先判断发送用户是否在这个群内,避免出现精心构造好的包
user, err := msgIn.GetSender(true)
if checkError(err) != nil {
continue
}
_, err = contain(msgIn.To, user.Groups)
if err != nil {
checkError(fmt.Errorf("user %s not in group %d: %s", user.UserName, msgIn.To, err))
continue
}
} else {
// 如果是发给个人的消息
// 判断是否有接收者
_, err = msgIn.GetReceiver(false)
if checkError(err) != nil {
continue
}
}
// 这里对文件消息,如果是文件消息则将之放入缓存(暂时不向接收端发送,等待客户端文件发送完毕后再向接收端发送)
if msgIn.Isfile {
filecache = GetFilecache()
filecache.Lock()
filecache.cache[msgIn.ID] = &msgIn
filecache.Unlock()
if err := msgIn.connection.Emit("file-receipt", receipt{
msgIn.ID,
msgIn.Sync,
200,
"next",
}); err != nil {
checkError(err)
}
} else {
// 不是文件消息
// 将消息放至消息队列中
msgOutCh <- msgIn
}
}

```

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: d40d12247406459987090dff2000f973444e5079

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.