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 }
|
unsafe { (*self.raw).len as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_slice(&self) -> &'payload [u8] {
|
pub fn as_slice(&self) -> &[u8] {
|
||||||
unsafe {
|
unsafe {
|
||||||
core::slice::from_raw_parts((*self.raw).payload as *const u8,
|
core::slice::from_raw_parts((*self.raw).payload as *const u8,
|
||||||
(*self.raw).len as usize)
|
(*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 {
|
unsafe {
|
||||||
core::slice::from_raw_parts_mut((*self.raw).payload as *mut u8,
|
core::slice::from_raw_parts_mut((*self.raw).payload as *mut u8,
|
||||||
(*self.raw).len as usize)
|
(*self.raw).len as usize)
|
||||||
|
|
|
@ -447,10 +447,10 @@ impl<'a> Read for TcpStream<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let (pbuf, pos) = self.buffer.take().unwrap();
|
let (pbuf, pos) = self.buffer.take().unwrap();
|
||||||
let slice = &pbuf.as_slice()[pos..];
|
let remaining = pbuf.len() - pos;
|
||||||
let len = ::std::cmp::min(buf.len(), slice.len());
|
let len = ::std::cmp::min(buf.len(), remaining);
|
||||||
buf[..len].copy_from_slice(&slice[..len]);
|
buf[..len].copy_from_slice(&pbuf.as_slice()[pos..pos + len]);
|
||||||
if len < slice.len() {
|
if len < remaining {
|
||||||
self.buffer = Some((pbuf, pos + len))
|
self.buffer = Some((pbuf, pos + len))
|
||||||
}
|
}
|
||||||
Ok(len)
|
Ok(len)
|
||||||
|
|
Loading…
Reference in New Issue