From nobody Thu May 2 16:37:57 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=1626099978; cv=none; d=zohomail.com; s=zohoarc; b=jKcvyv5NtGkkAXu2GaqJsI4Taxm0IPXV9VCYx6XgbZiuFMsI8FR4gUOdF/XemM/RuyYh+qNiPqhccBjcr16M3gRFPmM9zLl/hi3l7wYPC0QMAQL97gAsh87FnNSMuJdRMgmL7pRUbiyAwQM914F95IIWyHL8LoSM3gASKRco328= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626099978; 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=WbIUxTihVLnRDr/ixWvabRfgIjJ0UUUDV8zn3DWGvS4=; b=R4edDSy/833wzcGc5Ucxg6OJF98zBJmnzYcEb5tBZYIToGSfLMw1j6yhOLipZ7k3dSuh3uGuZtIgSh99x8h82B1HHRmKBciAlQ8rNwcRdI+729+6rmdRKCRXq6OHCnoFYFzM7bxS+unOk4+B6NHDIJ4RXldma29YNJUZG9i8x0c= 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 1626099978589660.7283627343465; Mon, 12 Jul 2021 07:26:18 -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-531-uAFZVq6VMBOPjIqLEptkhg-1; Mon, 12 Jul 2021 10:26:16 -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 93351100C66A; Mon, 12 Jul 2021 14:26:10 +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 56EBF10074FC; Mon, 12 Jul 2021 14:26:08 +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 5F45F1809C99; Mon, 12 Jul 2021 14:26:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16CEQ4Fw006936 for ; Mon, 12 Jul 2021 10:26:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4EB9B5C22A; Mon, 12 Jul 2021 14:26:04 +0000 (UTC) Received: from andariel.lan (unknown [10.40.192.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id C70835C1D1 for ; Mon, 12 Jul 2021 14:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626099977; 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=WbIUxTihVLnRDr/ixWvabRfgIjJ0UUUDV8zn3DWGvS4=; b=TM69v9g4TuM0TarW6to9HgPRWbEOHmrLtCoPJylFnNZTS6ZbXGu2btEKEvMGxsXwCZO6G9 ejrgjNge4RnVg3GDUr/wvVzs9LyAVegdAG1BqPIvSUzkzxaRQaaXm6CgFdV8ZV2lJ0GiXK NQItzikBUlGQypLlF6tqTj57Q8ZCGJg= X-MC-Unique: uAFZVq6VMBOPjIqLEptkhg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH] qemu: Fix crash in virQEMUCapsProbeQMPTPM Date: Mon, 12 Jul 2021 16:25:59 +0200 Message-Id: <8ee829746b19cbd990c711867584ba851f3a10b3.1626099947.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 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) X-ZM-MESSAGEID: 1626099978967100001 Content-Type: text/plain; charset="utf-8" If the queried QMP command doesn't exist qemuMonitorGetTPMModels returns 0 but sets the string list to NULL which isn't accepted by g_strv_contains. Fixes: a5bc5f0ecf8 Reported-by: Olaf Hering Signed-off-by: Peter Krempa --- src/qemu/qemu_capabilities.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d1cd8f11ac..5b359258a1 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3168,6 +3168,9 @@ virQEMUCapsProbeQMPTPM(virQEMUCaps *qemuCaps, if (qemuMonitorGetTPMModels(mon, &models) < 0) return -1; + if (!models) + return 0; + for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsTPMModelsToCaps); i++) { const char *needle =3D virDomainTPMModelTypeToString(virQEMUCapsTP= MModelsToCaps[i].type); if (g_strv_contains((const char **)models, needle)) @@ -3177,10 +3180,12 @@ virQEMUCapsProbeQMPTPM(virQEMUCaps *qemuCaps, if (qemuMonitorGetTPMTypes(mon, &types) < 0) return -1; - for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsTPMTypesToCaps); i++) { - const char *needle =3D virDomainTPMBackendTypeToString(virQEMUCaps= TPMTypesToCaps[i].type); - if (g_strv_contains((const char **)types, needle)) - virQEMUCapsSet(qemuCaps, virQEMUCapsTPMTypesToCaps[i].caps); + if (types) { + for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsTPMTypesToCaps); i++) { + const char *needle =3D virDomainTPMBackendTypeToString(virQEMU= CapsTPMTypesToCaps[i].type); + if (g_strv_contains((const char **)types, needle)) + virQEMUCapsSet(qemuCaps, virQEMUCapsTPMTypesToCaps[i].caps= ); + } } return 0; --=20 2.31.1