summaryrefslogtreecommitdiffstats
path: root/src/resolve
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-04-24 23:36:03 +0200
committerLennart Poettering <lennart@poettering.net>2020-05-07 14:39:44 +0200
commita258f4915a2674d77e656755e5a4fa23059f778a (patch)
treea3e3d921a74c2daafb2890af3c260907b265fd95 /src/resolve
parentRevert "Add Kensington SlimBlade Trackball" (diff)
downloadsystemd-a258f4915a2674d77e656755e5a4fa23059f778a.tar.xz
systemd-a258f4915a2674d77e656755e5a4fa23059f778a.zip
tree-wide: use CMSG_SPACE() (and not CMSG_LEN()) to allocate control buffers
We need to use the CMSG_SPACE() macro to size the control buffers, not CMSG_LEN(). The former is rounded up to next alignment boundary, the latter is not. The former should be used for allocations, the latter for encoding how much of it is actually initialized. See cmsg(3) man page for details about this. Given how confusing this is, I guess we don't have to be too ashamed here, in most cases we actually did get this right.
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/resolved-manager.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 1849fc1b1d..69630cf49d 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -962,10 +962,10 @@ static int manager_ipv4_send(
struct in_pktinfo *pi;
mh.msg_control = &control;
- mh.msg_controllen = CMSG_LEN(sizeof(struct in_pktinfo));
+ mh.msg_controllen = sizeof(control);
cmsg = CMSG_FIRSTHDR(&mh);
- cmsg->cmsg_len = mh.msg_controllen;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_PKTINFO;
@@ -1021,10 +1021,10 @@ static int manager_ipv6_send(
struct in6_pktinfo *pi;
mh.msg_control = &control;
- mh.msg_controllen = CMSG_LEN(sizeof(struct in6_pktinfo));
+ mh.msg_controllen = sizeof(control);
cmsg = CMSG_FIRSTHDR(&mh);
- cmsg->cmsg_len = mh.msg_controllen;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
cmsg->cmsg_level = IPPROTO_IPV6;
cmsg->cmsg_type = IPV6_PKTINFO;