]> granicus.if.org Git - strace/commitdiff
Fix one more code pattern that might break gcc strict aliasing rules
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 19 May 2016 01:23:40 +0000 (01:23 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 21 May 2016 09:33:12 +0000 (09:33 +0000)
* socketutils.c (receive_responses): Turn static buffer into a union
to avoid breaking of gcc strict aliasing rules.
* tests/netlink_inet_diag.c (check_responses): Likewise.
* tests/netlink_netlink_diag.c (check_responses): Likewise.
* tests/netlink_unix_diag.c (check_responses): Likewise.

socketutils.c
tests/netlink_inet_diag.c
tests/netlink_netlink_diag.c
tests/netlink_unix_diag.c

index a0d9310d9cc559c9e2576674c0ce41b44bb59e1b..5d8d3ed98802b9c17be185c0c17e238f0f5daa49 100644 (file)
@@ -187,13 +187,17 @@ receive_responses(const int fd, const unsigned long inode,
                  int (* parser) (const char *, const void *,
                                  int, unsigned long))
 {
-       static long buf[8192 / sizeof(long)];
+       static union {
+               struct nlmsghdr hdr;
+               long buf[8192 / sizeof(long)];
+       } hdr_buf;
+
        struct sockaddr_nl nladdr = {
                .nl_family = AF_NETLINK
        };
        struct iovec iov = {
-               .iov_base = buf,
-               .iov_len = sizeof(buf)
+               .iov_base = hdr_buf.buf,
+               .iov_len = sizeof(hdr_buf.buf)
        };
        int flags = 0;
 
@@ -212,7 +216,7 @@ receive_responses(const int fd, const unsigned long inode,
                        return false;
                }
 
-               const struct nlmsghdr *h = (struct nlmsghdr *) buf;
+               const struct nlmsghdr *h = &hdr_buf.hdr;
                if (!NLMSG_OK(h, ret))
                        return false;
                for (; NLMSG_OK(h, ret); h = NLMSG_NEXT(h, ret)) {
index 342be072ae45380a808ac8997409b2a4cb0f07c7..2332e203af0b49f7bfd6352d38e3cdfe3372ebb0 100644 (file)
@@ -75,13 +75,17 @@ send_query(const int fd, const int family, const int proto)
 static void
 check_responses(const int fd)
 {
-       static long buf[8192 / sizeof(long)];
+       static union {
+               struct nlmsghdr hdr;
+               long buf[8192 / sizeof(long)];
+       } hdr_buf;
+
        struct sockaddr_nl nladdr = {
                .nl_family = AF_NETLINK
        };
        struct iovec iov = {
-               .iov_base = buf,
-               .iov_len = sizeof(buf)
+               .iov_base = hdr_buf.buf,
+               .iov_len = sizeof(hdr_buf.buf)
        };
        struct msghdr msg = {
                .msg_name = (void *) &nladdr,
@@ -94,7 +98,7 @@ check_responses(const int fd)
        if (ret <= 0)
                perror_msg_and_skip("recvmsg");
 
-       struct nlmsghdr *h = (struct nlmsghdr *) buf;
+       struct nlmsghdr *h = &hdr_buf.hdr;
        if (!NLMSG_OK(h, ret))
                error_msg_and_skip("!NLMSG_OK");
        if (h->nlmsg_type == NLMSG_ERROR) {
index 0afdb5d7791f1e3b8692f0145d58300322a86b49..fc32822b178d4a0a5056a9113764f8014ad5a812 100644 (file)
@@ -80,13 +80,17 @@ send_query(const int fd)
 static void
 check_responses(const int fd)
 {
-       static long buf[8192 / sizeof(long)];
+       static union {
+               struct nlmsghdr hdr;
+               long buf[8192 / sizeof(long)];
+       } hdr_buf;
+
        struct sockaddr_nl nladdr = {
                .nl_family = AF_NETLINK
        };
        struct iovec iov = {
-               .iov_base = buf,
-               .iov_len = sizeof(buf)
+               .iov_base = hdr_buf.buf,
+               .iov_len = sizeof(hdr_buf.buf)
        };
        struct msghdr msg = {
                .msg_name = (void *) &nladdr,
@@ -99,7 +103,7 @@ check_responses(const int fd)
        if (ret <= 0)
                perror_msg_and_skip("recvmsg");
 
-       struct nlmsghdr *h = (struct nlmsghdr *) buf;
+       struct nlmsghdr *h = &hdr_buf.hdr;
        if (!NLMSG_OK(h, ret))
                error_msg_and_skip("!NLMSG_OK");
        if (h->nlmsg_type == NLMSG_ERROR) {
index e5ef6fab3ef389042a9f2b0a43f9efd35bbd65d6..b91cbbbe2afa392a72bb7c679b016cb95d340ef4 100644 (file)
@@ -83,13 +83,17 @@ send_query(const int fd)
 static void
 check_responses(const int fd)
 {
-       static long buf[8192 / sizeof(long)];
+       static union {
+               struct nlmsghdr hdr;
+               long buf[8192 / sizeof(long)];
+       } hdr_buf;
+
        struct sockaddr_nl nladdr = {
                .nl_family = AF_NETLINK
        };
        struct iovec iov = {
-               .iov_base = buf,
-               .iov_len = sizeof(buf)
+               .iov_base = hdr_buf.buf,
+               .iov_len = sizeof(hdr_buf.buf)
        };
        struct msghdr msg = {
                .msg_name = (void *) &nladdr,
@@ -102,7 +106,7 @@ check_responses(const int fd)
        if (ret <= 0)
                perror_msg_and_skip("recvmsg");
 
-       struct nlmsghdr *h = (struct nlmsghdr *) buf;
+       struct nlmsghdr *h = &hdr_buf.hdr;
        if (!NLMSG_OK(h, ret))
                error_msg_and_skip("!NLMSG_OK");
        if (h->nlmsg_type == NLMSG_ERROR) {