Skip to content
  • Peter Hutterer's avatar
    os: append, rather than prepend, any new input thread fds · 2df2815d
    Peter Hutterer authored
    
    
    xf86AddEnabledDevice() prepends the new fd to the list,
    xf86RemoveEnabledDevice() then searches for a matching fd and removes that
    entry. If this is done for the same fd (and since we lose all information but
    the actual fd) we usually unregister virtual devices in reverse order, causing
    a dereference of already released memory.
    
    Case in point:
    - the wacom driver calls xf86AddEnabledDevice() once for the physical device,
      then multiple times for the virtual subdevices
    - when the physical device is unplugged, the driver calls
      xf86RemoveEnabledDevice() for the physical device
    - all we have is the fd, so we end up removing the last virtual device from
      the fd set
    - xf86DeleteInput() frees the physical device's pInfo
    - the fd goes crazy with ENODEV, but a read_input() now passes the already
      freed pInfo for the physical device
    - boom
    
    Fix this by appending to the fd list to provide bug-for-bug compatibility with
    the old SIGIO code. This needs to be fixed in the driver, but meanwhile not
    crashing the server provides for better user experience.
    
    Signed-off-by: default avatarPeter Hutterer <peter.hutterer@who-t.net>
    Reviewed-by: default avatarKeith Packard <keithp@keithp.com>
    2df2815d