From 20793828c401587636f0b50473ae5ca5292f1082 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 22 Jun 2017 15:26:18 -0700 Subject: [PATCH] tcpd: fix bug in partial reads that was breaking https in curl --- src/tcpd/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tcpd/main.rs b/src/tcpd/main.rs index 9ee1d240ad..1c3a881ccc 100644 --- a/src/tcpd/main.rs +++ b/src/tcpd/main.rs @@ -316,13 +316,15 @@ impl Tcpd { while ! handle.todo_read.is_empty() && (! handle.data.is_empty() || handle.read_closed()) { let (_timeout, mut packet) = handle.todo_read.pop_front().unwrap(); let buf = unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }; - if let Some((_ip, tcp)) = handle.data.pop_front() { - let mut i = 0; - while i < buf.len() && i < tcp.data.len() { - buf[i] = tcp.data[i]; - i += 1; + if let Some((ip, mut tcp)) = handle.data.pop_front() { + let len = std::cmp::min(buf.len(), tcp.data.len()); + for (i, c) in tcp.data.drain(0..len).enumerate() { + buf[i] = c; } - packet.a = i; + if !tcp.data.is_empty() { + handle.data.push_front((ip, tcp)); + } + packet.a = len; } else { packet.a = 0; }