1
0
mirror of https://github.com/systemd/systemd synced 2026-03-19 19:44:48 +01:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Franck Bui
9952f11a84
Merge pull request #20039 from yuwata/sd-device-get-sysattr-value-embedded-nul
sd-device: allow to read sysattr which contains embedded NUL
2021-06-28 15:43:29 +02:00
Yu Watanabe
70160c6eee sd-device: allow to read sysattr which contains embedded NUL
This effectively reverts the commit 2a394d0bf2f0afd8b9ed5faeb33f23459e3c6504.

But drop trailing '\r' of the read value, as sd_device_set_sysattr_value() drops it.

Fixes #20025.
2021-06-26 10:48:28 +09:00

View File

@ -2022,13 +2022,17 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr,
/* skip non-readable files */ /* skip non-readable files */
return -EPERM; return -EPERM;
else { else {
/* read attribute value */ size_t size;
r = read_full_virtual_file(path, &value, NULL);
/* 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) if (r < 0)
return r; return r;
/* drop trailing newlines */ /* 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 /* Unfortunately, we need to return 'const char*' instead of 'char*'. Hence, failure in caching