Skip to content

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Jul 16, 2021

In CAddrMan::ResetI2PPorts() we copy addr_info to
addr_info_newport, change the port in the latter and eventually, if
necessary, we overwrite addr_info with addr_info_newport.

The problem is that after creating the copy, addr_info.nRandomPos may
be changed by ClearNew() -> Delete() -> SwapRandom(). Later,
overwriting the entire addr_info with the stale addr_info_newport
would restore the previous/stale nRandomPos.

To fix that change just the port in addr_info.

Fixes #22467

vasild added 2 commits July 16, 2021 12:38
In `CAddrMan::ResetI2PPorts()` we copy `addr_info` to
`addr_info_newport`, change the `port` in the latter and eventually, if
necessary, we overwrite `addr_info` with `addr_info_newport`.

The problem is that after creating the copy, `addr_info.nRandomPos` may
be changed by `ClearNew() -> Delete() -> SwapRandom()`. Later,
overwriting the entire `addr_info` with the stale `addr_info_newport`
would restore the previous/stale `nRandomPos`.

To fix that change just the port in `addr_info`.

Fixes bitcoin#22467
It is not necessary to have a separate variable `addr_info_newport`, we
can directly change the port in `addr_info`.
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 84b624e

Running fuzzer and ran units with 24cad63 cherry picked on this branch.

@jonatack
Copy link
Member

Still fuzzing with your last three pulls cherry-picked together + running on mainnet with DEBUG_ADDRMAN.

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@fanquake
Copy link
Member

Closing now that #22497 has been merged.

@fanquake fanquake closed this Jul 20, 2021
@vasild vasild deleted the reset_i2p_ports_no_overwrite_pos branch July 20, 2021 05:50
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion `nRndPos1 < vRandom.size() && nRndPos2 < vRandom.size()' failed

5 participants