Skip to content

Multiheader::preallocate causes an uninitialized value to be dereferenced #1990

@djkoloski

Description

@djkoloski

In src/sys/socket/mod.rs, Multiheader::preallocate allocates a vec or MaybeUninit::uninit() and then passes each address.as_mut_ptr() to pack_mhdr_to_receive. pack_mhdr_to_receive in turn performs (*address).as_mut_ptr(), which results in undefined behavior.

To support this desired behavior SockaddrLikePriv must change the signature of as_mut_ptr to fn(*mut Self) -> *mut libc::sockaddr and use ptr::addr_of_mut! to access fields in implementations. It does not appear that performing *mut S as *mut libc::sockaddr is possible because () implements SockaddrLike but returns null_mut() from its SockaddrLikePriv implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions