mirror of https://github.com/m-labs/artiq.git
runtime: fix a lifetime issue in lwip::Pbuf.
This would have allowed a use-after-move (or -free) to typecheck.
This commit is contained in:
parent
f68e4ae519
commit
668928a16c
|
@ -267,14 +267,14 @@ impl<'payload> Pbuf<'payload> {
|
|||
unsafe { (*self.raw).len as usize }
|
||||
}
|
||||
|
||||
pub fn as_slice(&self) -> &'payload [u8] {
|
||||
pub fn as_slice(&self) -> &[u8] {
|
||||
unsafe {
|
||||
core::slice::from_raw_parts((*self.raw).payload as *const u8,
|
||||
(*self.raw).len as usize)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_mut_slice(&mut self) -> &'payload mut [u8] {
|
||||
pub fn as_mut_slice(&mut self) -> &mut [u8] {
|
||||
unsafe {
|
||||
core::slice::from_raw_parts_mut((*self.raw).payload as *mut u8,
|
||||
(*self.raw).len as usize)
|
||||
|
|
|
@ -447,10 +447,10 @@ impl<'a> Read for TcpStream<'a> {
|
|||
}
|
||||
|
||||
let (pbuf, pos) = self.buffer.take().unwrap();
|
||||
let slice = &pbuf.as_slice()[pos..];
|
||||
let len = ::std::cmp::min(buf.len(), slice.len());
|
||||
buf[..len].copy_from_slice(&slice[..len]);
|
||||
if len < slice.len() {
|
||||
let remaining = pbuf.len() - pos;
|
||||
let len = ::std::cmp::min(buf.len(), remaining);
|
||||
buf[..len].copy_from_slice(&pbuf.as_slice()[pos..pos + len]);
|
||||
if len < remaining {
|
||||
self.buffer = Some((pbuf, pos + len))
|
||||
}
|
||||
Ok(len)
|
||||
|
|
Loading…
Reference in New Issue