diff --git a/network/fuzz/Cargo.toml b/network/fuzz/Cargo.toml index c04cc37762..f4eb181c01 100644 --- a/network/fuzz/Cargo.toml +++ b/network/fuzz/Cargo.toml @@ -13,7 +13,7 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" -ipnetwork = "0.18" +ipnetwork = "0.20.0" [dependencies.ckb-network] path = ".." diff --git a/network/fuzz/fuzz_targets/fuzz_addr_manager.rs b/network/fuzz/fuzz_targets/fuzz_addr_manager.rs index f4665c0512..d788ae9bfa 100644 --- a/network/fuzz/fuzz_targets/fuzz_addr_manager.rs +++ b/network/fuzz/fuzz_targets/fuzz_addr_manager.rs @@ -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()) diff --git a/network/fuzz/src/lib.rs b/network/fuzz/src/lib.rs index 94138a6b27..32e680c541 100644 --- a/network/fuzz/src/lib.rs +++ b/network/fuzz/src/lib.rs @@ -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() } @@ -25,8 +29,7 @@ impl<'a> BufManager<'a> { self.offset += len; r } else { - let mut r = Vec::::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 @@ -138,6 +141,6 @@ impl FromBytes 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() } }