Skip to content

Unaligned pointer access when setting device name in VirtualDeviceBuilder #162

@Fsmount

Description

@Fsmount

when setting a device name using VirtualDeviceBuilder::name(), the crate attempts to write to an unaligned pointer, causing UB, this i believe occurs specifically when copying the device name string into the uinput_setup struct

to reproduce:

  1. create a minimal device
use evdev::{uinput::VirtualDevice, UinputAbsSetup};

fn main() -> Result<()> {
    VirtualDevice::builder()?
        .name("test device name") // Triggers UB
        .build()?;
    Ok(())
}
  1. run it under a debugger
  2. look for the following error message(for context i used lldb added a br at VirtualDevice::builder(), then inspected val.name.data_ptr)
unaligned pointer: ptr::read_volatile requires aligned pointer
unsafe precondition violated: is_aligned_to: align is not a power-of-two

Expected behaviour

the crate should safely handle string copying without triggering unaligned access UB

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