Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe unsound in new? #3

Open
lwz23 opened this issue Dec 9, 2024 · 0 comments
Open

Maybe unsound in new? #3

lwz23 opened this issue Dec 9, 2024 · 0 comments

Comments

@lwz23
Copy link

lwz23 commented Dec 9, 2024

Hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:

pub fn new(bytes: *const [u8]) -> Result<Elf<'a>, ElfError> {
        let bytes = unsafe { &*bytes };
        for i in 0..100 {
            dprint!("{} ", bytes[i]);
            if i % 10 == 9 {
                dprintln!();
            }
        }
        let elf = unsafe {
            let data: *const ElfHeader = bytes.as_ptr() as *const ElfHeader;
            &*(data)
        };
        dprintln!("{:?}", elf);
        if elf.magic != ELF_MAGIC {
            return Err(ElfError::InvalidMagic);
        }
        Ok(Elf { bytes, elf })
    }

I think there may exist a unsound problem in this function. there is no test for the bytes, if the user pass a null pointer to this function it will lead to UB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant