From nobody Mon Feb 9 12:11:29 2026 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