lkml.org 
[lkml]   [2024]   [Feb]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v2 1/4] rust: uaccess: add userspace pointers
On Thu, Feb 8, 2024 at 4:48 PM Alice Ryhl <aliceryhl@google.com> wrote:
> + /// Reads the entirety of the user slice, appending it to the end of the
> + /// provided buffer.
> + ///
> + /// Fails with `EFAULT` if the read encounters a page fault.
> + pub fn read_all(mut self, buf: &mut Vec<u8>) -> Result<()> {
> + buf.try_reserve(self.length)?;
> +
> + // SAFETY: The call to `try_reserve` was successful, so the spare
> + // capacity is at least `self.length` bytes long.
> + unsafe { self.read_raw(buf.spare_capacity_mut().as_mut_ptr().cast(), self.length)? };
> +
> + // SAFETY: Since the call to `read_raw` was successful, so the next
> + // `len` bytes of the vector have been initialized.
> + unsafe { buf.set_len(buf.len() + self.length) };
> + Ok(())
> + }

There's a bug here, since read_raw changes self.length. It will be
fixed in the next version.

Alice

\
 
 \ /
  Last update: 2024-05-27 15:14    [W:0.200 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site