Smithay/udev-rs

Enumerating devices on older versions of libudev (eg 215) segfaults

anelson opened this issue · 0 comments

The fix in #13 employs a workaround (the author called it a "hack" so I will do the same, no offence intended) to a segfault that was caused by older versions of libudev asserting that the struct udev* parameter was non-NULL. The hack is to pass a bogus non-null pointer to somewhere in the process where an arbitrary empty slice is located. This apparently works in newer libudev versions because this struct udev* parameter is apparently not used for anything.

However, in older versions this is not the case (I don't know when this started, but I can confirm that it's the case in version 215, shipping with Debian 8 "jessie"). As least in 215, libudev assumes this is a valid struct udev* created with the udev_new() function, and when it's not, the process segfaults.

This hack is dangerous also because it's relying on undocumented behavior that could easily change in the future. The current libudev manpage explicitly says that functions require a valid struct udev* context:

All functions require a libudev context to operate. This context can
be create via udev_new(3). It is used to track library state and link
objects together. No global state is used by libudev, everything is
always linked to a udev context.

I'll prepare a PR with a safer, more permanent fix for this issue.