nervosnetwork / ckb

The Nervos CKB is a public permissionless blockchain, and the layer 1 of Nervos network.
https://www.nervos.org
MIT License
1.14k stars 224 forks source link

Add fuzz on network #4468

Closed joii2020 closed 1 month ago

joii2020 commented 1 month ago

Use fuzz to test some code of the network. Found a bug: AddrManager::fetch_random

When count is 0 and addr_infos.push(addr_info);(on line 69) has already been executed, checking if addr_infos.len() == count will definitely return false. At this point, it will continue executing all of self.random_ids before returning. I believe that in this case, when count is 0, it should immediately return an empty Vec.

driftluo commented 1 month ago

From an algorithmic level, this is a problem. From the perspective of network working mechanism, count can never be 0