Red Hat Bugzilla – Bug 1302359
udev_device_get_sysattr_value () does not consistently return contents of sys attribute file
Last modified: 2018-02-14 18:06:35 EST
Created attachment 1118822 [details]
Simple reproducer that works on my machine for this particular boot.
Description of problem:
udev_device_get_sysattr_value() is defined to return the contents of a sys attr file. In some cases, it doesn't.
Version-Release number of selected component (if applicable):
Consistently, for the particular devices and attributes chosen. It is not clear what it is about the particular attribute file that causes the behavior.
Steps to Reproduce:
1. My reproducer contains two examples of devices that behave differently.
2. Run the reproducer. Note that both devices have vpg_pg83 attribute files that are non-empty (wc claims that both contain characters, and cat echos random glyphs to the terminal in both cases).
3. Note that in one case, the result of calling udev_deivce_get_sysattr_value is the empty string and that in the other case it is a non-empty string.
Inconsistent behavior in reading non-empty vpg_pg83 attribute file for different devices.
I think this also affects the behavior of udevadm info --attribute-walk for these devices. AFAIU, udevadm is defined not to show binary attributes, restricting itself to those that are matched in udev rules. For the device where the method returns a non-empty string, udevadm does not show a corresponding vpd_pg83 attribute. For the device where the function mistakenly returns an empty string, udevadm does show the attribute, apparently interpreting it, since empty, as matchable text.
It looks like the value stops at the first 0x00 character.
In my reproducer, with the device that returns a non-empty string, only part of the data is returned, since the null character occurs after two characters. With the device that returns an empty string, the null character is the first character, so the empty string is returned.
IMHO, this is not a bug, by definition of udev_device_get_sysattr_value(), it returns a string, so truncate after first \0 found is reasonable.
In case of reading file like vpd83, you could manually read it or ask udev team to create new function like
'udev_device_get_sysattr_value_raw(struct udev_device *udev_device, const char *sysattr, uint8_t *buff, size_t buff_max_size))'.
Sorry, I missed the part you are asking for consistency. Please ignore my previous comment.