1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

Merge pull request #20039 from yuwata/sd-device-get-sysattr-value-embedded-nul

sd-device: allow to read sysattr which contains embedded NUL
This commit is contained in:
Franck Bui 2021-06-28 15:43:29 +02:00 committed by GitHub
commit 9952f11a84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2022,13 +2022,17 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr,
/* skip non-readable files */
return -EPERM;
else {
/* read attribute value */
r = read_full_virtual_file(path, &value, NULL);
size_t size;
/* Read attribute value, Some attributes contain embedded '\0'. So, it is necessary to
* also get the size of the result. See issue #20025. */
r = read_full_virtual_file(path, &value, &size);
if (r < 0)
return r;
/* drop trailing newlines */
delete_trailing_chars(value, "\n");
while (size > 0 && strchr(NEWLINE, value[--size]))
value[size] = '\0';
}
/* Unfortunately, we need to return 'const char*' instead of 'char*'. Hence, failure in caching