diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-06-23 12:56:34 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-06-30 10:35:27 +0200 |
commit | 7d9337ed77b08ee691568172e7c074d2b5d8e15e (patch) | |
tree | aa5921097cc5e68549a8e72b1e975526c1a09e30 /src/libsystemd/sd-netlink/netlink-message.c | |
parent | man: document sd_bus_message_read_strv_extend() (diff) | |
download | systemd-7d9337ed77b08ee691568172e7c074d2b5d8e15e.tar.xz systemd-7d9337ed77b08ee691568172e7c074d2b5d8e15e.zip |
sd-netlink: allow sd_netlink_message_read() to be used for union types
Before, sd_netlink_message_read() expected to fill a buffer completely,
and would return -EIO if the attribute being read was shorter than the
buffer. This means that the function can be used to "peek" into attributes
(by specifying a short buffer to just read part of the attribute), but
cannot be used to read something into a union without knowing beforehand
which specific field in the union is being filled. That latter operation
seems more useful (messages are short, so we don't really need to do partial
reads), so let's allow reads that don't fill the output buffer completely.
Diffstat (limited to '')
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-message.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c index dafc16f258..34b4c23bd5 100644 --- a/src/libsystemd/sd-netlink/netlink-message.c +++ b/src/libsystemd/sd-netlink/netlink-message.c @@ -741,11 +741,11 @@ _public_ int sd_netlink_message_read(sd_netlink_message *m, unsigned short type, if (r < 0) return r; - if ((size_t) r < size) - return -EIO; + if ((size_t) r > size) + return -ENOBUFS; if (data) - memcpy(data, attr_data, size); + memcpy(data, attr_data, r); return r; } |