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

koinotice/vite: rpcapi/api/filters/subscribe.go; 44 LoC

Open
#12,327 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 [koinotice/vite](https://www.github.com/koinotice/vite) at [rpcapi/api/filters/subscribe.go](https://github.com/koinotice/vite/blob/96daba76ca626f9d96227227bb01283208634864/rpcapi/api/filters/subscribe.go#L556-L599)

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

[Click here to see the code in its original context.](https://github.com/koinotice/vite/blob/96daba76ca626f9d96227227bb01283208634864/rpcapi/api/filters/subscribe.go#L556-L599)

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

```go
for addr, hr := range filterParam.addrRange {
startHeight := hr.fromHeight
endHeight := hr.toHeight
acc, err := s.vite.Chain().GetLatestAccountBlock(addr)
if err != nil {
return nil, err
}
if acc == nil {
continue
}
if startHeight == 0 {
startHeight = 1
}
if endHeight == 0 || endHeight > acc.Height {
endHeight = acc.Height
}
for {
offset, count, finish := getHeightPage(startHeight, endHeight, getAccountBlocksCount)
if count == 0 {
break
}
startHeight = offset + 1
blocks, err := s.vite.Chain().GetAccountBlocksByHeight(addr, offset, count)
if err != nil {
return nil, err
}
for i := len(blocks); i > 0; i-- {
if blocks[i-1].LogHash != nil {
list, err := s.vite.Chain().GetVmLogList(blocks[i-1].LogHash)
if err != nil {
return nil, err
}
for _, l := range list {
if filterLog(filterParam, l) {
logs = append(logs, &Logs{l, blocks[i-1].Hash, api.Uint64ToString(blocks[i-1].Height), &addr, false})
}
}
}
}
if finish {
break
}
}
}

```

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: 96daba76ca626f9d96227227bb01283208634864

Contributor guide

No contributing guide indexed for this repository

Research direction

Read rpcapi/api/filters/subscribe.go around lines 556-599, starting with the analyzer warning about addr in the Logs composite literal. Check the surrounding filter and Logs usage to determine whether the referenced address is preserved as intended. Done means leaving the requested reaction classification: Bug, Mitigated, or Desirable Behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.