Skip to content

Maybe unsound in IOBuff::Buf #1354

Description

@lwz23

Hello, thank you for your contribution in this work. I'm scanning rust project for unsound problem.
I notice the following code.

pub struct IOBuff {
    pub addr: u64,
    pub size: usize,
}

impl IOBuff {
....................................
    pub fn Buf(&self) -> &'static mut [u8] {
        let ptr = self.addr as *mut u8;
        let toSlice = unsafe { slice::from_raw_parts_mut(ptr, self.size) };

        return toSlice;
    }
......................................
}

considering IOBuff is a pub struct and addr is a pub field, I;m not sure whether user can directlt create and assign addr field. And with the direct call to slice::from_raw_parts_mut(ptr, self.size) which may result in UB. I am not sure whether user can direct call the Buf method, if it is not for external using, maybe we should mark it as unsafe or pub(crate)? I brought this up for security reasons, so please don't mind if this is a false report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions