sockets: Initialize the whole ancillary data buffer not only the actual struct
[strongswan.git] / src / libcharon / plugins / socket_dynamic / socket_dynamic_socket.c
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));
                }