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

ggg-geyi/pcapbeat: beater/pcapbeat.go; 62 LoC

Open
#14,229 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 [ggg-geyi/pcapbeat](https://www.github.com/ggg-geyi/pcapbeat) at [beater/pcapbeat.go](https://github.com/ggg-geyi/pcapbeat/blob/098b276b09aec2cf4603a11eecd8a7ca484094ce/beater/pcapbeat.go#L86-L147)

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.

> range-loop variable filePath used in defer or goroutine at line 115

[Click here to see the code in its original context.](https://github.com/ggg-geyi/pcapbeat/blob/098b276b09aec2cf4603a11eecd8a7ca484094ce/beater/pcapbeat.go#L86-L147)

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

```go
for index, filePath := range filePathSlice{
logp.Info("=========== READY DEAL PCAP FILE =======")
newPath := ""

// 先将文件重命名dealing。标示这个文件正在被处理
if path, error := utils.RenamePcapFileToDealing(filePath); error != nil{
logp.Err("RENAME .PCAP TO .DEALING ERROR.ERROR MSG IS : 。",error.Error())
continue
}else{
newPath = path
logp.Info("RENAME .PCAP TO .DEALING ", filePath, " ---> ",newPath)
}
logp.Info("REANDY DEALING FILE PATH IS : ", index, filePath)

// 创建带缓冲的chan。这个chan用来存放的就是http的req和resp合并之后的记录
packetChan := make(chan http.CombineHttpRecord,10)

// 开启一个协程去处理数据
go analysis.ReadPcapAndDealProtocols(packetChan, newPath)

// 开启协程准备发送数据
go func(newPath string, packetChan chan http.CombineHttpRecord) {
for x := range packetChan {
event := beat.Event{
Timestamp: time.Now(),

Fields: common.MapStr{
//"type": b.Info.Name,
"type": "http", // 将协议类型自动修正为http
"filepath": filePath,
"client_ip": x.Pk.Net.Src().String(),
"server": x.Pk.Net.Dst().String(),
"ip": x.Ip,
"client_port": x.Pk.Transport.Src().String(),
"port": x.Pk.Transport.Dst().String(),
"http": common.MapStr{
"response": common.MapStr{
"code": x.HttpResponseCode,
},
},

"status": x.Status,
"bytes_in": x.BytesIn,
"bytes_out": x.BytesOut,
"path": x.Path,
"method": x.Method,
"query": x.Query,
"responsetime": x.Responsetime,
},
}
bt.client.Publish(event)
}

logp.Info("READY TO RENAME .dealing TO .done",newPath)
if _, error := utils.RenamePcapDealingFileToDone(newPath); error != nil{
logp.Err("RENAME .dealing TO .done ERROR. PATH IS : ",newPath," AND MESSAGE IS : ",error.Error())
}else{
logp.Info("DONE RENAME .dealing TO .done",newPath)
}

}(newPath, packetChan)
}

```

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: 098b276b09aec2cf4603a11eecd8a7ca484094ce

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.