sockets: Initialize the whole ancillary data buffer not only the actual struct
authorTobias Brunner <tobias@strongswan.org>
Tue, 10 Sep 2013 11:40:16 +0000 (13:40 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 10 Sep 2013 11:42:59 +0000 (13:42 +0200)
This avoids uninitialized bytes that Valgrind seems to notice otherwise.

Fixes #395.

src/libcharon/plugins/socket_default/socket_default_socket.c
src/libcharon/plugins/socket_dynamic/socket_dynamic_socket.c

index 4139afe..3aa09be 100644 (file)
@@ -445,6 +445,7 @@ METHOD(socket_t, sender, status_t,
 #elif defined(IP_SENDSRCADDR)
                        char buf[CMSG_SPACE(sizeof(struct in_addr))];
 #endif
+                       memset(buf, 0, sizeof(buf));
                        msg.msg_control = buf;
                        msg.msg_controllen = sizeof(buf);
                        cmsg = CMSG_FIRSTHDR(&msg);
@@ -453,7 +454,6 @@ METHOD(socket_t, sender, status_t,
                        cmsg->cmsg_type = IP_PKTINFO;
                        cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
                        pktinfo = (struct in_pktinfo*)CMSG_DATA(cmsg);
-                       memset(pktinfo, 0, sizeof(struct in_pktinfo));
                        addr = &pktinfo->ipi_spec_dst;
 #elif defined(IP_SENDSRCADDR)
                        cmsg->cmsg_type = IP_SENDSRCADDR;
@@ -471,6 +471,7 @@ METHOD(socket_t, sender, status_t,
                        struct in6_pktinfo *pktinfo;
                        struct sockaddr_in6 *sin;
 
+                       memset(buf, 0, sizeof(buf));
                        msg.msg_control = buf;
                        msg.msg_controllen = sizeof(buf);
                        cmsg = CMSG_FIRSTHDR(&msg);
@@ -478,7 +479,6 @@ METHOD(socket_t, sender, status_t,
                        cmsg->cmsg_type = IPV6_PKTINFO;
                        cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
                        pktinfo = (struct in6_pktinfo*)CMSG_DATA(cmsg);
-                       memset(pktinfo, 0, sizeof(struct in6_pktinfo));
                        sin = (struct sockaddr_in6*)src->get_sockaddr(src);
                        memcpy(&pktinfo->ipi6_addr, &sin->sin6_addr, sizeof(struct in6_addr));
                }
index abbc8ba..012f18e 100644 (file)
@@ -572,6 +572,7 @@ METHOD(socket_t, sender, status_t,
                        char buf[CMSG_SPACE(sizeof(struct in_pktinfo))];
                        struct in_pktinfo *pktinfo;
 
+                       memset(buf, 0, sizeof(buf));
                        msg.msg_control = buf;
                        msg.msg_controllen = sizeof(buf);
                        cmsg = CMSG_FIRSTHDR(&msg);
@@ -579,7 +580,6 @@ METHOD(socket_t, sender, status_t,
                        cmsg->cmsg_type = IP_PKTINFO;
                        cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
                        pktinfo = (struct in_pktinfo*)CMSG_DATA(cmsg);
-                       memset(pktinfo, 0, sizeof(struct in_pktinfo));
                        addr = &pktinfo->ipi_spec_dst;
                        sin = (struct sockaddr_in*)src->get_sockaddr(src);
                        memcpy(addr, &sin->sin_addr, sizeof(struct in_addr));
@@ -590,6 +590,7 @@ METHOD(socket_t, sender, status_t,
                        struct in6_pktinfo *pktinfo;
                        struct sockaddr_in6 *sin;
 
+                       memset(buf, 0, sizeof(buf));
                        msg.msg_control = buf;
                        msg.msg_controllen = sizeof(buf);
                        cmsg = CMSG_FIRSTHDR(&msg);
@@ -597,7 +598,6 @@ METHOD(socket_t, sender, status_t,
                        cmsg->cmsg_type = IPV6_PKTINFO;
                        cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
                        pktinfo = (struct in6_pktinfo*)CMSG_DATA(cmsg);
-                       memset(pktinfo, 0, sizeof(struct in6_pktinfo));
                        sin = (struct sockaddr_in6*)src->get_sockaddr(src);
                        memcpy(&pktinfo->ipi6_addr, &sin->sin6_addr, sizeof(struct in6_addr));
                }