Commit 6e80d044 authored by Alice Ryhl's avatar Alice Ryhl Committed by Isaac Manjarres
Browse files

FROMGIT: rust: uaccess: add UserSliceReader::strcpy_into_buf



This patch adds a more convenient method for reading C strings from
userspace. Logic is added to NUL-terminate the buffer when necessary so
that a &CStr can be returned.

Note that we treat attempts to read past `self.length` as a fault, so
this returns EFAULT if that limit is exceeded before `buf.len()` is
reached.

Reviewed-by: default avatarDanilo Krummrich <dakr@kernel.org>
Signed-off-by: default avatarAlice Ryhl <aliceryhl@google.com>
Reviewed-by: default avatarBenno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250616-strncpy-from-user-v5-2-2d3fb0e1f5af@google.com


[ Use `from_mut` to clean `clippy::ref_as_ptr` lint. Reworded
  title. - Miguel ]
Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>

Bug: 414339114
(cherry picked from commit 17bbbefb
 https://github.com/Rust-for-Linux/linux.git

 rust-next)
Change-Id: I285c99788ff2e2bc3f9f9b6bbc2746dd454002f5
Signed-off-by: default avatarAlice Ryhl <aliceryhl@google.com>
parent 0cb01a7d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment