From nobody Sun May 12 10:14:46 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=1694077374; cv=none; d=zohomail.com; s=zohoarc; b=aOKDNyDzJgvKk9qB0EN9qQTDvsPEpfiUeDhc8k2mZtHjdjjF4zMw5MRIFS35arvcVDc6UB0vlSZ1CLREE62WpvlJkIlYPit0I4PPZZ4/xPbcoaBfbz+GFH1KzKXBjtzG5Xge3PkwOl3xZG2TNT9ws8KxgbsF9c6T16QoXhRnEos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694077374; 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=sEdgWUGeJx8ZRjqFeoK5hnyfmC01WfIJGzKrbkQGY/g=; b=UhIqNHxBUYpRqXO48kXXVMtSGAf81Drjc68JWlrZ4SnTQIhRdLLR9/AW92yY8LC2APf4rpidVFnxS5n0G7mGYFcORyGqxMQ8JMRDUxwSaZlaloobdAIRvRQqq9ugq0rhobiuka8GAuygS5pzzRrEfp60dckBFFK8x8avjigjLkY= 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 1694077374243271.72067878811424; Thu, 7 Sep 2023 02:02:54 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-694-n16QmVbvMZmoWeIdnJKPbQ-1; Thu, 07 Sep 2023 05:02:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 685FF1C09CDA; Thu, 7 Sep 2023 09:02:49 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 525011121320; Thu, 7 Sep 2023 09:02:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C47D41946597; Thu, 7 Sep 2023 09:02:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CAF68194658F for ; Thu, 7 Sep 2023 09:02:45 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B60672026D2B; Thu, 7 Sep 2023 09:02:45 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D2F82026D76 for ; Thu, 7 Sep 2023 09:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694077373; 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=sEdgWUGeJx8ZRjqFeoK5hnyfmC01WfIJGzKrbkQGY/g=; b=b+tMS+PT8cgpyoRPDDhfJob4mibMVgWc0meUQ8eFERtYknGdBTC0Nf/p4PnWTuCpQsPAyT oDf7VMIr+b5/oBigG+DjS/tUUvfE+92VSmVJL3V0WP3lN55j5YOvLbkFL4kU/OV47UVMBu E3FXnn+pPtq8NkY69ASBLo9RmFA3MGA= X-MC-Unique: n16QmVbvMZmoWeIdnJKPbQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virsh-snapshot: Avoid passing NULL to qsort() in virshSnapshotListCollect() Date: Thu, 7 Sep 2023 11:02:42 +0200 Message-ID: <85e9f4fa5375fb8acc42e46d173b20ec77c6f08a.1694077362.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1694077375476100001 Content-Type: text/plain; charset="utf-8"; x-default="true" If a domain has no snapshots and 'virsh snapshot-list' is called, this gets all the way down to virshSnapshotListCollect() which then collects all snapshots (none), and passes them to qsort() which doesn't like being called with NULL: extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __nonnull ((1, 4)); Resolves: https://gitlab.com/libvirt/libvirt/-/issues/533 Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- tools/virsh-snapshot.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index d7889a38e4..ecb935b2b4 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1310,9 +1310,11 @@ virshSnapshotListCollect(vshControl *ctl, virDomainP= tr dom, } } } - if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL)) + if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL) && + snaplist->snaps) { qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps), virshSnapSorter); + } snaplist->nsnaps -=3D deleted; =20 ret =3D g_steal_pointer(&snaplist); --=20 2.41.0