Skip to content

Safety hazard in Clipboard::new #7743

@SuchAFuriousDeath

Description

@SuchAFuriousDeath

Describe the bug
I believe that this method:

pub fn new(_raw_display_handle: Option<RawDisplayHandle>) -> Self {
is not supposed to be safe.

It calls this method from smithay-clipboard (with the smithay-clipboard feature on): https://github.com/Smithay/smithay-clipboard/blob/26c2f53f15f6bdc4f41a442d0ae2c2d63bbc617c/src/lib.rs#L34, however, the safety requirements of that method cannot be guaranteed to be upheld by egui-winit.

    /// # Safety
    ///
    /// `display` must be a valid `*mut wl_display` pointer, and it must remain
    /// valid for as long as `Clipboard` object is alive.
    pub unsafe fn new(display: *mut c_void) -> Self { ... }

To Reproduce
I believe that this is enough of an issue in theory, but here is a minimal demonstration of the safety hazard with 100% safe code: https://github.com/SuchAFuriousDeath/smithay-clipboard-segfault. The code in the repo segfaults when dropping the Clipboard.

Expected behavior
I believe the method should be unsafe and pass the safety requirement onto the caller just like the smithay-clipboard method does.

Additional context
I believe this might be the cause of #7660, but I consider this distant enough to warrant a separate issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions