]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Clear CMSG_SPACE(sizeof(data)) in cmsghdr to appease valgrind. 8005/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 28 Jun 2019 09:25:32 +0000 (11:25 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 1 Jul 2019 08:21:46 +0000 (10:21 +0200)
(cherry picked from commit 20b22895546a3e7fb7760940599dfb1e29a00777)

pdns/misc.cc

index 1f90bbcbd14c4ff8bf98c9d7d8729f712ed73bc7..a051b7e20c3c790adec75193880bb78a65627e0b 100644 (file)
@@ -900,7 +900,8 @@ void addCMsgSrcAddr(struct msghdr* msgh, void* cmsgbuf, const ComboAddress* sour
     cmsg->cmsg_len = CMSG_LEN(sizeof(*pkt));
 
     pkt = (struct in6_pktinfo *) CMSG_DATA(cmsg);
-    memset(pkt, 0, sizeof(*pkt));
+    // Include the padding to stop valgrind complaining about passing uninitialized data
+    memset(pkt, 0, CMSG_SPACE(sizeof(*pkt)));
     pkt->ipi6_addr = source->sin6.sin6_addr;
     pkt->ipi6_ifindex = itfIndex;
   }
@@ -917,7 +918,8 @@ void addCMsgSrcAddr(struct msghdr* msgh, void* cmsgbuf, const ComboAddress* sour
     cmsg->cmsg_len = CMSG_LEN(sizeof(*pkt));
 
     pkt = (struct in_pktinfo *) CMSG_DATA(cmsg);
-    memset(pkt, 0, sizeof(*pkt));
+    // Include the padding to stop valgrind complaining about passing uninitialized data
+    memset(pkt, 0, CMSG_SPACE(sizeof(*pkt)));
     pkt->ipi_spec_dst = source->sin4.sin_addr;
     pkt->ipi_ifindex = itfIndex;
 #elif defined(IP_SENDSRCADDR)
@@ -931,7 +933,9 @@ void addCMsgSrcAddr(struct msghdr* msgh, void* cmsgbuf, const ComboAddress* sour
     cmsg->cmsg_type = IP_SENDSRCADDR;
     cmsg->cmsg_len = CMSG_LEN(sizeof(*in));
 
+    // Include the padding to stop valgrind complaining about passing uninitialized data
     in = (struct in_addr *) CMSG_DATA(cmsg);
+    memset(in, 0, CMSG_SPACE(sizeof(*in)));
     *in = source->sin4.sin_addr;
 #endif
   }