tcpd: Fix behavior when reading to small buffer

This commit is contained in:
Ian Douglas Scott 2017-04-07 18:36:09 -07:00
parent ae4bcb43e7
commit e695897fe8
No known key found for this signature in database
GPG key ID: 4924E10E199B5959

View file

@ -574,12 +574,16 @@ impl SchemeMut for Tcpd {
Handle::Tcp(ref mut handle) => {
if ! handle.is_connected() {
return Err(Error::new(ENOTCONN));
} else if let Some((_ip, tcp)) = handle.data.pop_front() {
} else if let Some((ip, mut tcp)) = handle.data.pop_front() {
let mut i = 0;
while i < buf.len() && i < tcp.data.len() {
buf[i] = tcp.data[i];
let mut len = std::cmp::min(buf.len(), tcp.data.len());
for c in tcp.data.drain(0..len) {
buf[i] = c;
i += 1;
}
if !tcp.data.is_empty() {
handle.data.push_front((ip, tcp));
}
return Ok(i);
} else if handle.flags & O_NONBLOCK == O_NONBLOCK || handle.read_closed() {