Don't panic on packet data (#6769)

This commit is contained in:
Jack May
2019-11-06 14:32:37 -08:00
committed by GitHub
parent 29f3b198cf
commit 65de227520
4 changed files with 10 additions and 9 deletions

View File

@ -973,10 +973,13 @@ impl Archiver {
socket.send_to(&serialized_req, to).unwrap(); socket.send_to(&serialized_req, to).unwrap();
let mut buf = [0; 1024]; let mut buf = [0; 1024];
if let Ok((size, _addr)) = socket.recv_from(&mut buf) { if let Ok((size, _addr)) = socket.recv_from(&mut buf) {
return bincode::config() // Ignore bad packet and try again
if let Ok(slot) = bincode::config()
.limit(PACKET_DATA_SIZE as u64) .limit(PACKET_DATA_SIZE as u64)
.deserialize(&buf[..size]) .deserialize(&buf[..size])
.unwrap(); {
return slot;
}
} }
sleep(Duration::from_millis(500)); sleep(Duration::from_millis(500));
} }

View File

@ -1183,8 +1183,8 @@ impl ClusterInfo {
"cluster_info-gossip_pull_request_verify_fail", "cluster_info-gossip_pull_request_verify_fail",
1 1
); );
} else if caller.contact_info().is_some() { } else if let Some(contact_info) = caller.contact_info() {
if caller.contact_info().unwrap().id == me.read().unwrap().gossip.id { if contact_info.id == me.read().unwrap().gossip.id {
warn!("PullRequest ignored, I'm talking to myself"); warn!("PullRequest ignored, I'm talking to myself");
inc_new_counter_debug!("cluster_info-window-request-loopback", 1); inc_new_counter_debug!("cluster_info-window-request-loopback", 1);
} else { } else {

View File

@ -43,9 +43,7 @@ impl ShredSigVerifier {
let slot_end = slot_start + size_of::<u64>(); let slot_end = slot_start + size_of::<u64>();
trace!("slot {} {}", slot_start, slot_end,); trace!("slot {} {}", slot_start, slot_end,);
if slot_end <= packet.meta.size { if slot_end <= packet.meta.size {
let slot: u64 = limited_deserialize(&packet.data[slot_start..slot_end]).ok()
limited_deserialize(&packet.data[slot_start..slot_end]).ok()?;
Some(slot)
} else { } else {
None None
} }

View File

@ -179,8 +179,8 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for ShortVec<T> {
/// Return the decoded value and how many bytes it consumed. /// Return the decoded value and how many bytes it consumed.
pub fn decode_len(bytes: &[u8]) -> Result<(usize, usize), Box<bincode::ErrorKind>> { pub fn decode_len(bytes: &[u8]) -> Result<(usize, usize), Box<bincode::ErrorKind>> {
let short_len: ShortU16 = bincode::deserialize(bytes)?; let short_len: ShortU16 = bincode::deserialize(bytes)?;
let num_bytes = bincode::serialized_size(&short_len).unwrap() as usize; let num_bytes = bincode::serialized_size(&short_len)?;
Ok((short_len.0 as usize, num_bytes)) Ok((short_len.0 as usize, num_bytes as usize))
} }
#[cfg(test)] #[cfg(test)]