Skip to content

Commit

Permalink
runtime: fix a lifetime issue in lwip::Pbuf.
Browse files Browse the repository at this point in the history
This would have allowed a use-after-move (or -free) to typecheck.
whitequark committed Dec 5, 2016
1 parent f68e4ae commit 668928a
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions artiq/runtime.rs/liblwip/lib.rs
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 4 additions & 4 deletions artiq/runtime.rs/src/sched.rs
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 668928a

Please sign in to comment.