[CRIU] [PATCH 09/10] util-net: Workaround for strict-aliasing problem

Cyrill Gorcunov gorcunov at openvz.org
Sat Apr 14 16:43:58 EDT 2012


Problem seems to be in some compler versions,
so lets try to workaround the problem.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 util-net.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/util-net.c b/util-net.c
index 090a8d7..a15183b 100644
--- a/util-net.c
+++ b/util-net.c
@@ -1,3 +1,4 @@
+#include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 
@@ -23,6 +24,7 @@ static void scm_fdset_init_chunk(struct scm_fdset *fdset, int nr_fds)
 static int *scm_fdset_init(struct scm_fdset *fdset, struct sockaddr_un *saddr,
 		int saddr_len, bool with_flags)
 {
+	struct cmsghdr tmp;
 	struct cmsghdr *cmsg;
 
 	BUILD_BUG_ON(CR_SCM_MAX_FD > SCM_MAX_FD);
@@ -39,10 +41,19 @@ static int *scm_fdset_init(struct scm_fdset *fdset, struct sockaddr_un *saddr,
 	fdset->hdr.msg_control		= &fdset->msg_buf;
 	fdset->hdr.msg_controllen	= CMSG_LEN(sizeof(int) * CR_SCM_MAX_FD);
 
+	/*
+	 * gcc version 4.4.5 20110214 (Red Hat 4.4.5-6) (GCC)
+	 * issues strict aliasing rule violation if cmsg
+	 * members are accessed via pointer dereference while
+	 * gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC)
+	 * does not. So lets do plain memcopy here.
+	 */
 	cmsg				= CMSG_FIRSTHDR(&fdset->hdr);
-	cmsg->cmsg_len			= fdset->hdr.msg_controllen;
-	cmsg->cmsg_level		= SOL_SOCKET;
-	cmsg->cmsg_type			= SCM_RIGHTS;
+	tmp.cmsg_len			= fdset->hdr.msg_controllen;
+	tmp.cmsg_level			= SOL_SOCKET;
+	tmp.cmsg_type			= SCM_RIGHTS;
+
+	memcpy(cmsg, &tmp, sizeof(tmp));
 
 	return (int *)CMSG_DATA(cmsg);
 }
-- 
1.7.7.6



More information about the CRIU mailing list