Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ckb-network-fuzz: make cargo clippy happy #4767

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion network/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
ipnetwork = "0.18"
ipnetwork = "0.20.0"

[dependencies.ckb-network]
path = ".."
Expand Down
2 changes: 1 addition & 1 deletion network/fuzz/fuzz_targets/fuzz_addr_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn new_addr(data: &[u8], index: usize) -> AddrInfo {
// let ip = Ipv4Addr::from(((225 << 24) + index) as u32);
// let port = u16::from_le_bytes(data[4..6].try_into().unwrap());
let peer_id =
PeerId::from_bytes(vec![vec![0x12], vec![0x20], data[4..].to_vec()].concat()).unwrap();
PeerId::from_bytes([vec![0x12], vec![0x20], data[4..].to_vec()].concat()).unwrap();

AddrInfo::new(
format!("/ip4/{}/tcp/43/p2p/{}", ip, peer_id.to_base58())
Expand Down
6 changes: 3 additions & 3 deletions network/fuzz/fuzz_targets/fuzz_peer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ fn new_multi_addr(data: &mut BufManager) -> (MultiAddr, Flags) {
let buf = data.get_buf(16);
format!(
"/ip6/{}",
std::net::Ipv6Addr::from(u128::from_le_bytes(buf.try_into().unwrap())).to_string()
std::net::Ipv6Addr::from(u128::from_le_bytes(buf.try_into().unwrap()))
)
} else {
format!("/ip4/{}", data.get::<std::net::Ipv4Addr>().to_string())
format!("/ip4/{}", data.get::<std::net::Ipv4Addr>())
};

addr_str += &format!("/tcp/{}", data.get::<u16>());
Expand Down Expand Up @@ -66,7 +66,7 @@ fn add_basic_addr(data: &mut BufManager, peer_store: &mut PeerStore) {
for i in 0..num {
let addr = format!(
"/ip4/{}/tcp/43/p2p/{}",
std::net::Ipv4Addr::from(i as u32).to_string(),
std::net::Ipv4Addr::from(i),
PeerId::random().to_base58()
)
.parse()
Expand Down
9 changes: 6 additions & 3 deletions network/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ impl<'a> BufManager<'a> {
}
}

pub fn is_empty(&self) -> bool {
self.buf.is_empty()
}

pub fn len(&self) -> usize {
self.buf.len()
}
Expand All @@ -25,8 +29,7 @@ impl<'a> BufManager<'a> {
self.offset += len;
r
} else {
let mut r = Vec::<u8>::with_capacity(len);
r.resize(len, 0);
let mut r = vec![0; len];
r[0..(buf_len - self.offset)].copy_from_slice(&self.buf[self.offset..]);
self.offset = buf_len;
r
Expand Down Expand Up @@ -138,6 +141,6 @@ impl FromBytes<PeerId> for PeerId {
32
}
fn from_bytes(d: &[u8]) -> PeerId {
PeerId::from_bytes(vec![vec![0x12], vec![0x20], d.to_vec()].concat()).unwrap()
PeerId::from_bytes([vec![0x12], vec![0x20], d.to_vec()].concat()).unwrap()
}
}
Loading