From nobody Thu May 2 01:22:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1623668973; cv=none; d=zohomail.com; s=zohoarc; b=F10cpMlJm1hQl6eqQs+ZEmQP5WEMnidx3KCo6pvoeEXcuT8UsApHTLCz+1o7iRnYCxKjPQN6dKuh59i05+ejk3ftHfLz/uzkMQZGAvM2SdIbR/H5CDorDc1mgu1in67T7uc3ArRKVWNsBcqQtL2BGI6+r5WI7eecD/zgE7stqsI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623668973; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4lbQzM8lL/do8M5iVWS0RwzWwy8CQsuphpJfqdbyH0w=; b=GGl4IOSajoOcggV8y6POPWaWsQszY3llMTZLWHGcOjGHSt+rI3yOe4iJc1SxOPiZJQ/zdDTY446IXxTqyzthrHgDXsGL6o/iJFVnpcuT/ca6Zjt5vvWX6hhQIfHtq/LGoXbstlne0/55GuSwAAwcIrTcmbyFsbaqvh7t+X5BWMs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623668973889679.3524139215577; Mon, 14 Jun 2021 04:09:33 -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-491-USQ_XqsbObK0uR2awEb5kg-1; Mon, 14 Jun 2021 07:09:31 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id DB9F4107ACF6; Mon, 14 Jun 2021 11:09:25 +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 BA4EF60E3A; Mon, 14 Jun 2021 11:09:25 +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 81BB01809CBD; Mon, 14 Jun 2021 11:09:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15EB6Q3x017955 for ; Mon, 14 Jun 2021 07:06:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id A7D4310013C1; Mon, 14 Jun 2021 11:06:26 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18BF410016FE for ; Mon, 14 Jun 2021 11:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623668972; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4lbQzM8lL/do8M5iVWS0RwzWwy8CQsuphpJfqdbyH0w=; b=FnvLCobLmBKIf9eKxApoAz52akoo37dAq9++1UjAHvvRQp85SljkXPYroIMS69C3Pk+RIk Yz1yUlH+5nZ8Ate4BoYZSiG5a+ciCvjS0yS8ZtkXFyKPtl9Tpyfh6EtGoSxh/W9BnmN/ZL JmDjX9xnZ5h8TsvNJxbYH+vgN90ywo8= X-MC-Unique: USQ_XqsbObK0uR2awEb5kg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/3] Don't call qsort() over NULL Date: Mon, 14 Jun 2021 13:06:12 +0200 Message-Id: <9052c39d7ab1e17b152d88879f2fe8777491a310.1623668629.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In a few places it may happen that the array we want to sort is still NULL (e.g. because there were no leases found, no paths for secdriver to lock or no cache banks). However, passing NULL to qsort() is undefined and even though glibc plays nicely we shouldn't rely on undefined behaviour. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- src/conf/capabilities.c | 6 ++++-- src/security/security_manager.c | 3 ++- tools/nss/libvirt_nss.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 2f9a1e7d1f..d3b22f7dd0 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1924,8 +1924,10 @@ virCapabilitiesInitCaches(virCaps *caps) /* Sort the array in order for the tests to be predictable. This way = we can * still traverse the directory instead of guessing names (in case the= re is * 'index1' and 'index3' but no 'index2'). */ - qsort(caps->host.cache.banks, caps->host.cache.nbanks, - sizeof(*caps->host.cache.banks), virCapsHostCacheBankSorter); + if (caps->host.cache.banks) { + qsort(caps->host.cache.banks, caps->host.cache.nbanks, + sizeof(*caps->host.cache.banks), virCapsHostCacheBankSorter); + } =20 if (virCapabilitiesInitResctrlMemory(caps) < 0) goto cleanup; diff --git a/src/security/security_manager.c b/src/security/security_manage= r.c index d8b84e2861..0af581bc8b 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -1355,7 +1355,8 @@ virSecurityManagerMetadataLock(virSecurityManager *mg= r G_GNUC_UNUSED, * paths in the same order and thus no deadlock can occur. * Lastly, it makes searching for duplicate paths below * simpler. */ - qsort(paths, npaths, sizeof(*paths), cmpstringp); + if (paths) + qsort(paths, npaths, sizeof(*paths), cmpstringp); =20 for (i =3D 0; i < npaths; i++) { const char *p =3D paths[i]; diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index b021efc3c9..a6e8e4b12b 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -69,7 +69,8 @@ static void sortAddr(leaseAddress *tmpAddress, size_t ntmpAddress) { - qsort(tmpAddress, ntmpAddress, sizeof(*tmpAddress), leaseAddressSorter= ); + if (tmpAddress) + qsort(tmpAddress, ntmpAddress, sizeof(*tmpAddress), leaseAddressSo= rter); } =20 =20 --=20 2.31.1 From nobody Thu May 2 01:22:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1623668976; cv=none; d=zohomail.com; s=zohoarc; b=mg1kIqIOwSiw3fGlVxyylN0Yxf8R3aW4BAB/ugmMWFVbo5JZaiipAPHkW19dyCOvDlRnaVEqBOUuxTQoouzr4n1PS+z6jQQZtJVV9BCWZaDtTSDiMeYnB/aziiuqKO8+CL15V74DAfQK7dffuqkCP/QLbQ81AQQSGpzSaguk3rU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623668976; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZDMgrbuVO7VWt7QlVutjumZO9GlXPJKhot85q2mIJ8M=; b=YAswAb6311NIsBnWH9BzE2up1sMKyFugmTCZ+1UtlPQ6b5CYSmJI84PVj5UuiKcfq5MKog8K/iBuyjkGorJjicj0bmRHVnLvy+Bs5xpmwFu7kWxmxH3sGDWj6OxFwY5qvR3PnNqHHsck07frrWiV59Jo0EiijcrrrrmJMOA3Mjc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1623668976569907.9236808538695; Mon, 14 Jun 2021 04:09:36 -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-556-NQ3e8-cGPbyyuomu1WNNaw-1; Mon, 14 Jun 2021 07:09:33 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0BA31801B14; Mon, 14 Jun 2021 11:09:29 +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 D256C60E3A; Mon, 14 Jun 2021 11:09: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 981531D8A; Mon, 14 Jun 2021 11:09:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15EB6R7J017960 for ; Mon, 14 Jun 2021 07:06:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8206A10016FB; Mon, 14 Jun 2021 11:06:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06F6C10013C1 for ; Mon, 14 Jun 2021 11:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623668975; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZDMgrbuVO7VWt7QlVutjumZO9GlXPJKhot85q2mIJ8M=; b=czdKHjLye5BmeGQk5eZZHjd8LtGgW2TcjcM+GgISGTEyrz4tJ9JAyAgw2QolCGOSI76x6e zpDsgrZGw9xh+46fojRhBJxBmALbWR3WLkZ7JH699n1sT+h5/JBvtR+iQspKecMqxgFT3R A5ZbWwrDv2r/yf4820pTeBbj2aXAKXA= X-MC-Unique: NQ3e8-cGPbyyuomu1WNNaw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/3] tests: Don't pass INT_MAX to virFileReadAll() Date: Mon, 14 Jun 2021 13:06:13 +0200 Message-Id: <2a8bec4721c3e48f5eef4c1f96b9d397726cea76.1623668629.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In a few occasions in tests we pass INT_MAX to virFileReadLimFD(). This is not safe because virFileReadAll() will call virFileReadLimFD() under the hood which takes the limit and adds 1 to it. And since we use signed integer for all of this an overflow will occur. Signed-off-by: Michal Privoznik --- tests/networkxml2firewalltest.c | 2 +- tests/testutils.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltes= t.c index 91336a0c55..facbc20a0c 100644 --- a/tests/networkxml2firewalltest.c +++ b/tests/networkxml2firewalltest.c @@ -176,7 +176,7 @@ mymain(void) =20 basefile =3D g_strdup_printf("%s/networkxml2firewalldata/base.args", a= bs_srcdir); =20 - if (virFileReadAll(basefile, INT_MAX, &baseargs) < 0) + if (virFileReadAll(basefile, INT_MAX - 1, &baseargs) < 0) return EXIT_FAILURE; =20 DO_TEST("nat-default"); diff --git a/tests/testutils.c b/tests/testutils.c index eb3bd48b6a..4a63c6cc37 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -313,7 +313,7 @@ virTestLoadFileJSON(const char *p, ...) if (!(path =3D virTestLoadFileGetPath(p, ap))) goto cleanup; =20 - if (virFileReadAll(path, INT_MAX, &jsonstr) < 0) + if (virFileReadAll(path, INT_MAX - 1, &jsonstr) < 0) goto cleanup; =20 if (!(ret =3D virJSONValueFromString(jsonstr))) @@ -562,7 +562,7 @@ virTestCompareToFileFull(const char *actual, if (virTestLoadFile(filename, &filecontent) < 0 && !virTestGetRege= nerate()) return -1; } else { - if (virFileReadAll(filename, INT_MAX, &filecontent) < 0 && !virTes= tGetRegenerate()) + if (virFileReadAll(filename, INT_MAX - 1, &filecontent) < 0 && !vi= rTestGetRegenerate()) return -1; } =20 --=20 2.31.1 From nobody Thu May 2 01:22:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1623668968; cv=none; d=zohomail.com; s=zohoarc; b=P+5jlY46DzneT1V+eXqfBecmin/4FgnM56dgaLrZeIatL7wrAYe7xBcweNDBzaMrUnjMl3oWKPRRb+2UDiDZcGOGW/oo9zoOAzNZJu0SvwC/EYdX7wA6c0sID3oFxyv3OhAQl6xnNGYTZjEqWiesxowRY3PrWJcn4eBPK3yBsTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623668968; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NZ0pwwf2ZwD9iYEMaGaZ2AKkje/4hBntkDNUaj8QzF4=; b=LjD605p9jHcsbMCSprIUHFTQWQcQC3tJvugYNgegLvhhGoRf9aiTArG9wdkd9mT7TC3Ru8OKIesCZfsl+cyah04hiyYRpzvK18BFMbPDfrMHSiHiBvFj2icLgbvLuElRoXgd3517V90zc4CHPsg2grRzRapdkkYo0jNoA0hsoA8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623668968679603.7846561237156; Mon, 14 Jun 2021 04:09:28 -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-51-URjsJEhnNUuvPvNE7h3IOg-1; Mon, 14 Jun 2021 07:09:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A4A78015DB; Mon, 14 Jun 2021 11:09:21 +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 9FB805C22B; Mon, 14 Jun 2021 11:09: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 53C351809CBB; Mon, 14 Jun 2021 11:09:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15EB6SxD017968 for ; Mon, 14 Jun 2021 07:06:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6F49E10023B5; Mon, 14 Jun 2021 11:06:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAC4510013C1 for ; Mon, 14 Jun 2021 11:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623668967; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NZ0pwwf2ZwD9iYEMaGaZ2AKkje/4hBntkDNUaj8QzF4=; b=KjPPT8JzeAcPR8faifn9DivJ9k3euQfh3bQGTzK+9x/GLzIEO+jgnlTutTDuwDoS8LibAb EOHFwhqcQzOdwUUuSUUDMTRrEAxmliBuAWF94v9to4aQq8eILyuiupV81OB/jrzVfbhUyc vu9aOv4w+wvUMZSlkVu4DyqFmd3H1Fg= X-MC-Unique: URjsJEhnNUuvPvNE7h3IOg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/3] src: Use 1U for bit shifting Date: Mon, 14 Jun 2021 13:06:14 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In a few places we take 1 and shift it left repeatedly. So much that it won't longer fit into signed integer. The problem is that this is undefined behaviour. Switching to 1U makes us stay within boundaries. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- src/conf/domain_capabilities.h | 2 +- src/cpu/cpu_x86.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h index 69e90893cc..b6433b20c9 100644 --- a/src/conf/domain_capabilities.h +++ b/src/conf/domain_capabilities.h @@ -231,7 +231,7 @@ virDomainCapsCPUModelsGet(virDomainCapsCPUModels *cpuMo= dels, const char *name); =20 #define VIR_DOMAIN_CAPS_ENUM_IS_SET(capsEnum, value) \ - ((capsEnum).values & (1 << value)) + ((capsEnum).values & (1U << value)) =20 #define VIR_DOMAIN_CAPS_ENUM_SET(capsEnum, ...) \ do { \ diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index a4599499d0..a4792c21da 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2575,12 +2575,12 @@ cpuidSetLeafD(virCPUData *data, sub1 =3D *cpuid; for (sub =3D 2; sub < 64; sub++) { if (sub < 32 && - !(sub0.eax & (1 << sub)) && - !(sub1.ecx & (1 << sub))) + !(sub0.eax & (1U << sub)) && + !(sub1.ecx & (1U << sub))) continue; if (sub >=3D 32 && - !(sub0.edx & (1 << (sub - 32))) && - !(sub1.edx & (1 << (sub - 32)))) + !(sub0.edx & (1U << (sub - 32))) && + !(sub1.edx & (1U << (sub - 32)))) continue; =20 cpuid->ecx_in =3D sub; @@ -2614,7 +2614,7 @@ cpuidSetLeafResID(virCPUData *data, return -1; =20 for (sub =3D 1; sub < 32; sub++) { - if (!(res & (1 << sub))) + if (!(res & (1U << sub))) continue; cpuid->ecx_in =3D sub; cpuidCall(cpuid); --=20 2.31.1