From nobody Fri May 3 06:51:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595432319; cv=none; d=zohomail.com; s=zohoarc; b=O/yuVcH4XiKlSJPSu3I8rBAvMD3ekSISPMT2oygbD0pC4QcUFrib73MPRMbIcJevjKHgs+vD9L3EpxJWnyUW4viOnifKTjjgll1v7cUrQCAMEK5ML5wHis31wZyFjmprY/Bz2febhXtm7WldFvrPYAVqdLivojxdqP93X/4JrrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595432319; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=t7GQJDKspVngX2yWVvTC0Yni11zxTnIqN0y7y/4YG8k=; b=DZL4YjrWAoL4dEe4qipeWbd6p23HvzhgP68BVAPPiap7H817L5FeQqXMTX4RNUHKUygzk5FhNgDWnUp7jTipb+rct4wC3TAVJf74yZccbVB1/TjzFI5VE4YvOKwL0HIyMMEoDqr+yZR7EzNZ4MsA1tnAtUvaZMyBFaGshGpuptg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 159543231929789.28075239487578; Wed, 22 Jul 2020 08:38:39 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-7t7NQbCoPAWomnYAvhiHBw-1; Wed, 22 Jul 2020 11:38:34 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7A7419200C1; Wed, 22 Jul 2020 15:38:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7704510023A6; Wed, 22 Jul 2020 15:38:28 +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 8FA051809554; Wed, 22 Jul 2020 15:38:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06MFaeCE016707 for ; Wed, 22 Jul 2020 11:36:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1753D60C47; Wed, 22 Jul 2020 15:36:40 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7725B756A2; Wed, 22 Jul 2020 15:36:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595432318; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=t7GQJDKspVngX2yWVvTC0Yni11zxTnIqN0y7y/4YG8k=; b=CZ2319kVGk0KwdFv1VylT/dyCMjQQNkkraEYMLrSp51+9KzbG6NsBsyedOz4yLLFMspsai ElKmotDx2YP8AKzIOMUmpk8FuZ6TGPKRxfZD+PGJgfk5rqcyE9qg0Fzqa7IJdQqQyyZ6N8 jbl8sMsyo2V2GHqpmP8k8BTQZ8peElk= X-MC-Unique: 7t7NQbCoPAWomnYAvhiHBw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [PATCH] util: refactor code to workaround gcc 10.1.0 bug Date: Wed, 22 Jul 2020 16:36:28 +0100 Message-Id: <20200722153628.1844797-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) gcc 10.1.0 on Debian sid has a bug where the bounds checking gets confused beteen two branches: In file included from /usr/include/string.h:495, from ../../src/internal.h:28, from ../../src/util/virsocket.h:21, from ../../src/util/virsocketaddr.h:21, from ../../src/util/virnetdevip.h:21, from ../../src/util/virnetdevip.c:21: In function 'memcpy', inlined from 'virNetDevGetifaddrsAddress' at ../../src/util/virnetdevip= .c:914:13, inlined from 'virNetDevIPAddrGet' at ../../src/util/virnetdevip.c:962:1= 6: /usr/include/arm-linux-gnueabihf/bits/string_fortified.h:34:10: error: '__b= uiltin_memcpy' offset [16, 27] from the object at 'addr' is out of the boun= ds of referenced subobject 'inet4' with type 'struct sockaddr_in' at offset= 0 [-Werror=3Darray-bounds] 34 | return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__de= st)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~ In file included from ../../src/util/virnetdevip.h:21, from ../../src/util/virnetdevip.c:21: ../../src/util/virnetdevip.c: In function 'virNetDevIPAddrGet': ../../src/util/virsocketaddr.h:29:28: note: subobject 'inet4' declared here 29 | struct sockaddr_in inet4; | ^~~~~ cc1: all warnings being treated as errors Note the source location is pointing to the "inet6" / AF_INET6 branch of the "if", but is complaining about bounds of the "inet4" field. Changing the code into a switch() is sufficient to avoid triggering the bug and is arguably better code too. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/virnetdevip.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index ba9e567e5a..8b85c7beca 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -897,26 +897,25 @@ virNetDevGetifaddrsAddress(const char *ifname, } =20 for (ifa =3D ifap; ifa; ifa =3D ifa->ifa_next) { - int family; - if (STRNEQ_NULLABLE(ifa->ifa_name, ifname)) continue; =20 if (!ifa->ifa_addr) continue; - family =3D ifa->ifa_addr->sa_family; - - if (family !=3D AF_INET6 && family !=3D AF_INET) - continue; =20 - if (family =3D=3D AF_INET6) { + switch (ifa->ifa_addr->sa_family) { + case AF_INET6: addr->len =3D sizeof(addr->data.inet6); memcpy(&addr->data.inet6, ifa->ifa_addr, addr->len); - } else { + break; + case AF_INET: addr->len =3D sizeof(addr->data.inet4); memcpy(&addr->data.inet4, ifa->ifa_addr, addr->len); + break; + default: + continue; } - addr->data.stor.ss_family =3D family; + addr->data.stor.ss_family =3D ifa->ifa_addr->sa_family; ret =3D 0; goto cleanup; } --=20 2.24.1