github-vet / github-vet/rangeloop-pointer-findings
vrdchain/vrdchain: integration/rpctest/memwallet.go; 46 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [vrdchain/vrdchain](https://www.github.com/vrdchain/vrdchain) at [integration/rpctest/memwallet.go](https://github.com/vrdchain/vrdchain/blob/6d5351863076733128a16248bc5d3b7a3efc9265/integration/rpctest/memwallet.go#L416-L461)
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.
>
[Click here to see the code in its original context.](https://github.com/vrdchain/vrdchain/blob/6d5351863076733128a16248bc5d3b7a3efc9265/integration/rpctest/memwallet.go#L416-L461)
Click here to show the 46 line(s) of Go which triggered the analyzer.
```go
for outPoint, utxo := range m.utxos {
// Skip any outputs that are still currently immature or are
// currently locked.
if !utxo.isMature(m.currentHeight) || utxo.isLocked {
continue
}
amtSelected += utxo.value
// Add the selected output to the transaction, updating the
// current tx size while accounting for the size of the future
// sigScript.
tx.AddTxIn(wire.NewTxIn(&outPoint, nil, nil))
txSize = tx.SerializeSize() + spendSize*len(tx.TxIn)
// Calculate the fee required for the txn at this point
// observing the specified fee rate. If we don't have enough
// coins from he current amount selected to pay the fee, then
// continue to grab more coins.
reqFee := soterutil.Amount(txSize * int(feeRate))
if amtSelected-reqFee < amt {
continue
}
// If we have any change left over and we should create a change
// output, then add an additional output to the transaction
// reserved for it.
changeVal := amtSelected - amt - reqFee
if changeVal > 0 && change {
addr, err := m.newAddress()
if err != nil {
return err
}
pkScript, err := txscript.PayToAddrScript(addr)
if err != nil {
return err
}
changeOutput := &wire.TxOut{
Value: int64(changeVal),
PkScript: pkScript,
}
tx.AddTxOut(changeOutput)
}
return nil
}
```
Click here to show extra information the analyzer produced.
```
No path was found through the callgraph that could lead to a function which writes a pointer argument.
No path was found through the callgraph that could lead to a function which passes a pointer to third-party code.
root signature {NewTxIn 3} was not found in the callgraph; reference was passed directly to third-party code
```
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: 6d5351863076733128a16248bc5d3b7a3efc9265
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with integration/rpctest/memwallet.go lines 416-461 at commit 6d5351863076733128a16248bc5d3b7a3efc9265 and inspect the range over m.utxos, especially the pointer passed to wire.NewTxIn. Check the surrounding call path and determine whether the analyzer finding affects behavior; record the result as Bug, Mitigated, or Desirable Behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100