node: Make sure to only read packet-line header

If there is an unexpected error, eg. `BrokenPipe` in the upload process
process of the worker, we may have more than four bytes to read from the
remote socket. This change ensures that we don't attempt to read more
into a buffer of size `4`.
This commit is contained in:
Alexis Sellier 2023-03-16 15:24:27 +01:00
parent c46bc0cc82
commit 88c545bfdd
No known key found for this signature in database
1 changed files with 11 additions and 1 deletions

View File

@ -174,7 +174,7 @@ impl<G: Signer + Ecdh + 'static> Worker<G> {
log::debug!(target: "worker", "Waiting for `done` packet from remote..");
let mut header = [0; pktline::HEADER_LEN];
if let Ok(pktline::Packetline::Done) = pktline_r.read_pktline(&mut header) {
if let Ok(()) = pktline_r.read_done_pktline(&mut header) {
(WireSession::from_split_io(stream_r, stream_w), Err(err))
} else {
log::error!(
@ -460,6 +460,16 @@ pub mod pktline {
Ok((cmd, Vec::from(&pktline[..length])))
}
/// Parse a `done` packet-line.
pub fn read_done_pktline(&mut self, buf: &mut [u8]) -> io::Result<()> {
self.read_exact(&mut buf[..HEADER_LEN])?;
if &buf[..HEADER_LEN] == DONE_PKT {
return Ok(());
}
Err(io::ErrorKind::InvalidInput.into())
}
/// Parse a Git packet-line.
pub fn read_pktline(&mut self, buf: &mut [u8]) -> io::Result<Packetline> {
self.read_exact(&mut buf[..HEADER_LEN])?;