Revert "ANDROID: ashmem: use strncpy_from_user in set_name"
This reverts commit ba971cd36a.
Bug: 414339114
Change-Id: If44d5a7516c7dfdda68272f629ce30d74c84694f
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
This commit is contained in:
committed by
Isaac Manjarres
parent
603af016e4
commit
bd6df18cfd
@@ -297,16 +297,17 @@ impl MiscDevice for Ashmem {
|
||||
}
|
||||
|
||||
impl Ashmem {
|
||||
fn set_name(&self, reader: UserSliceReader) -> Result<isize> {
|
||||
fn set_name(&self, mut reader: UserSliceReader) -> Result<isize> {
|
||||
let mut local_name = [0u8; ASHMEM_NAME_LEN];
|
||||
let mut len = reader.strncpy_from_user(&mut local_name)?;
|
||||
reader.read_slice(&mut local_name)?;
|
||||
|
||||
// If the zero terminator is missing, the string is truncated to `ASHMEM_NAME_LEN-1` so
|
||||
// that `get_name` can return it and has enough space to add a zero terminator.
|
||||
if len == ASHMEM_NAME_LEN {
|
||||
len -= 1;
|
||||
local_name[len] = 0;
|
||||
}
|
||||
// Find the zero terminator. If the zero terminator is missing, the string is truncated to
|
||||
// `ASHMEM_NAME_LEN-1` so that `get_name` can return it and has enough space to add a zero
|
||||
// terminator.
|
||||
let len = local_name
|
||||
.iter()
|
||||
.position(|&c| c == 0)
|
||||
.unwrap_or(local_name.len() - 1);
|
||||
|
||||
let mut v = KVec::with_capacity(len, GFP_KERNEL)?;
|
||||
v.extend_from_slice(&local_name[..len], GFP_KERNEL)?;
|
||||
|
||||
@@ -294,19 +294,6 @@ impl UserSliceReader {
|
||||
unsafe { buf.inc_len(len) };
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reads a nul-terminated string into the provided buffer and returns the length.
|
||||
pub fn strncpy_from_user(self, buf: &mut [u8]) -> Result<usize> {
|
||||
let max = usize::min(self.length, buf.len()) as isize;
|
||||
// SAFETY: `buf` is valid for writing `buf.len()` bytes.
|
||||
let res =
|
||||
unsafe { bindings::strncpy_from_user(buf.as_mut_ptr(), self.ptr as *const u8, max) };
|
||||
if res >= 0 {
|
||||
Ok(res as usize)
|
||||
} else {
|
||||
Err(Error::from_errno(res as i32))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A writer for [`UserSlice`].
|
||||
|
||||
Reference in New Issue
Block a user