From nobody Thu May 2 07:16:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517420243097234.08426419174657; Wed, 31 Jan 2018 09:37:23 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B5FD53A9F7; Wed, 31 Jan 2018 17:37:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0FDE60BE3; Wed, 31 Jan 2018 17:37:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EFE2F5FBD8; Wed, 31 Jan 2018 17:37:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0VHbI4H024678 for ; Wed, 31 Jan 2018 12:37:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id A81115D6B7; Wed, 31 Jan 2018 17:37:18 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 080715D6A5; Wed, 31 Jan 2018 17:37:15 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 17:37:12 +0000 Message-Id: <20180131173712.29268-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: use union for sockaddr structs to avoid aliasing X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 31 Jan 2018 17:37:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: "Daniel P. Berrange" Some platforms/toolchains will complain about casting sockaddr_storage to sockaddr_un because it breaks strict aliasing rule ../../src/util/virutil.c: In function 'virGetUNIXSocketPath': ../../src/util/virutil.c:2005: error: dereferencing pointer 'un' does break= strict-aliasing rules [-Wstrict-aliasing] Change the code to use a union, in the same way that the virsocketaddr.h header does. Signed-off-by: Daniel P. Berrange --- Pushed as (yet another) CI build fix src/util/virutil.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index c23fa8f92e..cd6fbf2f30 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1985,30 +1985,33 @@ virGetListenFDs(void) #ifdef HAVE_SYS_UN_H char *virGetUNIXSocketPath(int fd) { - struct sockaddr_storage ss =3D { 0 }; - struct sockaddr_un *un =3D (struct sockaddr_un *)&ss; - socklen_t len =3D sizeof(ss); + union { + struct sockaddr sa; + struct sockaddr_storage ss; + struct sockaddr_un un; + } addr =3D { .ss =3D { 0 } }; + socklen_t len =3D sizeof(addr.ss); char *path; =20 - if (getsockname(fd, (struct sockaddr *)&ss, &len) < 0) { + if (getsockname(fd, &addr.sa, &len) < 0) { virReportSystemError(errno, _("Unable to get address of FD %d"), f= d); return NULL; } =20 - if (ss.ss_family !=3D AF_UNIX) { + if (addr.ss.ss_family !=3D AF_UNIX) { virReportSystemError(EINVAL, _("FD %d is not a UNIX socket, has af= =3D%d"), - fd, ss.ss_family); + fd, addr.ss.ss_family); return NULL; } =20 - if (un->sun_path[0] =3D=3D '\0') - un->sun_path[0] =3D '@'; + if (addr.un.sun_path[0] =3D=3D '\0') + addr.un.sun_path[0] =3D '@'; =20 - if (VIR_ALLOC_N(path, sizeof(un->sun_path) + 1) < 0) + if (VIR_ALLOC_N(path, sizeof(addr.un.sun_path) + 1) < 0) return NULL; =20 - memcpy(path, un->sun_path, sizeof(un->sun_path)); - path[sizeof(un->sun_path)] =3D '\0'; + memcpy(path, addr.un.sun_path, sizeof(addr.un.sun_path)); + path[sizeof(addr.un.sun_path)] =3D '\0'; return path; } =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list