Skip to content

Commit

Permalink
Fix missing batch length check (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets authored Oct 19, 2023
1 parent 5edd0eb commit 965c726
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions io/zenoh-transport/src/unicast/establishment/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,11 @@ pub(crate) async fn accept_link(link: &LinkUnicast, manager: &TransportManager)
.map_err(|e| (e, Some(close::reason::INVALID))));

log::debug!(
"New transport link accepted from {} to {}: {}",
"New transport link accepted from {} to {}: {}. Batch size: {}.",
osyn_out.other_zid,
manager.config.zid,
link
link,
state.zenoh.batch_size,
);

Ok(())
Expand Down
5 changes: 3 additions & 2 deletions io/zenoh-transport/src/unicast/establishment/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,11 @@ pub(crate) async fn open_link(
}

log::debug!(
"New transport link opened from {} to {}: {}",
"New transport link opened from {} to {}: {}. Batch size: {}.",
manager.config.zid,
iack_out.other_zid,
link
link,
state.zenoh.batch_size,
);

Ok(transport)
Expand Down
7 changes: 5 additions & 2 deletions io/zenoh-transport/src/unicast/lowlatency/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,11 @@ async fn rx_task_stream(
let mut length = [0_u8, 0_u8, 0_u8, 0_u8];
link.read_exact(&mut length).await?;
let n = u32::from_le_bytes(length) as usize;

link.read_exact(&mut buffer[0..n]).await?;
let len = buffer.len();
let b = buffer.get_mut(0..n).ok_or_else(|| {
zerror!("Batch len is invalid. Received {n} but negotiated max len is {len}.")
})?;
link.read_exact(b).await?;
Ok(n)
}

Expand Down
6 changes: 5 additions & 1 deletion io/zenoh-transport/src/unicast/universal/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ async fn rx_task_stream(
let mut length = [0_u8, 0_u8];
link.read_exact(&mut length).await?;
let n = BatchSize::from_le_bytes(length) as usize;
link.read_exact(&mut buffer[0..n]).await?;
let len = buffer.len();
let b = buffer.get_mut(0..n).ok_or_else(|| {
zerror!("Batch len is invalid. Received {n} but negotiated max len is {len}.")
})?;
link.read_exact(b).await?;
Ok(Action::Read(n))
}

Expand Down

0 comments on commit 965c726

Please sign in to comment.