From nobody Thu May 16 05:08:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1606823436; cv=none; d=zohomail.com; s=zohoarc; b=OVNHcyWMwoHpKAoIZ3+uLM9+b6gJJ2T2KjzbCB9S621i6szhHHUEa+4Nr1JYKZxNtZaIWgiaJUjabwJrn61sxJGBu/h1tpuoHfjGN5QJfcjqsfnsHXaCvMMZtgJX1Ho33BpZ7BJl8K9HL46wGuLgZQa59zfREf2vAl4toW7xT3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606823436; 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=MGcQcG/LIaxc6UxN95H4vbL0D0Q90IG4BjlwFH6VNY4=; b=AB68OhDS9tYNEK62ZkWCoQT9hH3zD1TJ8p1MF+Lpk3w8SpEA1cao3+LQXi7X8Fd3S/UBbWXOX0Lfx/xma2j/FKe7qGE1GKMC1Rn1ZQMCF6XXp2GyiFjfbFYXLN1ZoYUA/C801SaaS0ceNqhX2osD4OTgXCavVWxenPFSAkoMc+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606823436287671.8097957081592; Tue, 1 Dec 2020 03:50:36 -0800 (PST) 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-478-jraSQ5gjN7yQ3qsdlb886A-1; Tue, 01 Dec 2020 06:50:33 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D7F11005E55; Tue, 1 Dec 2020 11:50:27 +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 99B2319D7C; Tue, 1 Dec 2020 11:50:26 +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 EEB901809C9F; Tue, 1 Dec 2020 11:50:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B1BoMKN026321 for ; Tue, 1 Dec 2020 06:50:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 725335D72E; Tue, 1 Dec 2020 11:50:22 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id E83505D720 for ; Tue, 1 Dec 2020 11:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606823435; 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=MGcQcG/LIaxc6UxN95H4vbL0D0Q90IG4BjlwFH6VNY4=; b=eRNd3hRSiT3F20NcX/9HFfdkwV04/nnDN5L3TxeSz3LlPJo45UG1FhuhYyV8yBJq+JBrzt WyKr/Oi5j+Bu0vEnug/YTA7vLotPJARrSK0KbfqRavDUp83Xrv4iIuMl6vtZkle8QBwnmA vl3SuH1xp36NwjJsFoTT+BXIS+i1NGs= X-MC-Unique: jraSQ5gjN7yQ3qsdlb886A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/3] qemuDomainGetGuestInfo: Exit early if getting info fails Date: Tue, 1 Dec 2020 12:50:14 +0100 Message-Id: <90ec6fa05c49c87e0b5fdb0e315de8dd4a5ccc11.1606823325.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.23 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" If there is an error getting info from guest agent, then the control on qemuDomainGetGuestInfo() jumps onto 'exitagent' label and subsequently continues on 'endagentjob'. Both labels are hit also in success case, which is why there is a code that tries to match info obtained from the guest agent with domain definition. However, if we know that we've reached this area because of an error (ret =3D -1) there is no reason for us to attempt finding the match as the API as whole will end up with an error. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2d4b5a8b99..338c609854 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20129,6 +20129,9 @@ qemuDomainGetGuestInfo(virDomainPtr dom, endagentjob: qemuDomainObjEndAgentJob(vm); =20 + if (ret < 0) + goto cleanup; + if (nfs > 0 || ndisks > 0) { if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0) goto cleanup; --=20 2.26.2 From nobody Thu May 16 05:08:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1606823448; cv=none; d=zohomail.com; s=zohoarc; b=b7cCGRptj6boAkWg8MaSr3JfTCkQQzD8GirfjcCDeMMbOXwlcbh/9CjNa+Ior8sLt1XJJGAXVk5pfWGRA7VB/VTIrVYTRcNdroZjRri7TjAJeVO7BJZQN+OkfM7OrTFlY71wHlA+clIyogZNVAPFDJNlqPnJ4qk3XjuyxndE+KE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606823448; 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=aui1YywUSuyrEnk4jCUOFUJ//zkZLuoiU1lFqZCuQtc=; b=DEsnKXJmW3JF+om4mcdrsX8nxyiz2zLwm67ip6s9EP+ANuXWSz5uNX2J1Et8BvWCgm6QWfgc73kwkCJEYU+IHs1NVVSP7LNhkc5qW2K6TV2mO/4WNUHMKfijQaomS/Pw8692CcCyB1YH2IIC4NFK2XG00fV1+TtSWye08vlGlDM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606823448209670.5788233548171; Tue, 1 Dec 2020 03:50:48 -0800 (PST) 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-104-FUgUuueBOiGxGnNzpizc_Q-1; Tue, 01 Dec 2020 06:50:45 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D210E817B97; Tue, 1 Dec 2020 11:50:39 +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 ACD9E63B8C; Tue, 1 Dec 2020 11:50:39 +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 4657B1809CA4; Tue, 1 Dec 2020 11:50:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B1BoN2N026331 for ; Tue, 1 Dec 2020 06:50:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4CEE25D6AB; Tue, 1 Dec 2020 11:50:23 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id C32835D71D for ; Tue, 1 Dec 2020 11:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606823447; 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=aui1YywUSuyrEnk4jCUOFUJ//zkZLuoiU1lFqZCuQtc=; b=Sau9DK+o5E+ZwXhOgcNOolBDDYk31Sn0DeUC/Y3yq58ePTP6JjekgF3f/wZfM3/Ed7ZKTA DraTI2+7UKivgb+edoAmmTEVsu0ZpeOah9M/DOPD7ON4EWGUIT6S6P6EaC4fV5ZhQlLWge S72e8G3iFm2FgSJrYSZH0+kzRqxC+vA= X-MC-Unique: FUgUuueBOiGxGnNzpizc_Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/3] virJSONValueObjectGetStringArray: Report error if @key is not an array Date: Tue, 1 Dec 2020 12:50:15 +0100 Message-Id: <9bb03f05c4f04c575bc6560720703235eba35b74.1606823325.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.11 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" The virJSONValueObjectGetStringArray() function is given a @key which is supposed to be an array inside given @object. Well, if it's not then an error state is returned (NULL), but no error message is set. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virjson.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index d471923732..160f6172d2 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1472,8 +1472,12 @@ virJSONValueObjectGetStringArray(virJSONValuePtr obj= ect, const char *key) size_t i; =20 data =3D virJSONValueObjectGetArray(object, key); - if (!data) + if (!data) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("%s is missing not an array"), + key); return NULL; + } =20 n =3D virJSONValueArraySize(data); ret =3D g_new0(char *, n + 1); --=20 2.26.2 From nobody Thu May 16 05:08:46 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=1606823452; cv=none; d=zohomail.com; s=zohoarc; b=dg/e5TzWXFf/XK02JVabwNx+uk2zZqKWi8kihGsYW7ZPbVm6LzeqZvKl9TuOUSKsAfRbMCoT+cHmE3AtGrlYXHJQ/U/IwxHrSUyocWCOw2GOXuQWCgiM+akV8ECrs2XAoG1phml7J4enNcDnMycS7jV1cY600Fx+Nd1pbqFcH4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606823452; 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=S6KLE7m5rlI7QZrD6se/I5yCO1FXhh+7zT8iZqShAZQ=; b=BudtIyc37gskbTwV5RUciyiZjp3ihVWF1/pPSJFsuzDGP5uaecS3SKpb/yx8JK3JX/vvJ2AFhc0F1p6/bZ2hSQaBvwHAnX/jbhKfc9xn9rhBKeI4rJt7Xs2q+fzBpORDYEXYYQXjzWZ1xaaSVi1sPF0Ac00Q75Jgr3lZuHBXPHE= 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) header.from= 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 1606823452041644.0130292705921; Tue, 1 Dec 2020 03:50:52 -0800 (PST) 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-247--RS4V-NMMGyTewP2Ouj1mg-1; Tue, 01 Dec 2020 06:50:47 -0500 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 8418B1005E4C; Tue, 1 Dec 2020 11:50:42 +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 600FD5C1A3; Tue, 1 Dec 2020 11:50:42 +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 295074BB7B; Tue, 1 Dec 2020 11:50:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B1BoOrc026337 for ; Tue, 1 Dec 2020 06:50:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 293735D71D; Tue, 1 Dec 2020 11:50:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E5DE5D6AB for ; Tue, 1 Dec 2020 11:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606823451; 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=S6KLE7m5rlI7QZrD6se/I5yCO1FXhh+7zT8iZqShAZQ=; b=XpSJtxiAJnnOgcHpvEGFPJcYMthDLP8KsWinV0TYTgwmpMXCTPCDKvKvcacFQtpALkzxAT YPNfrGGNtubwNgI73mwzJ3Z9Z/JQu336lmda3+oORtdWOgMvWyF28e3hPMg2z51F+8VdY8 TC9Vh9DcTpTiMRmXp42HKJ8djON1/5M= X-MC-Unique: -RS4V-NMMGyTewP2Ouj1mg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/3] qemu: Use virJSONValueObjectGetStringArray() more Date: Tue, 1 Dec 2020 12:50:16 +0100 Message-Id: <639c6877576be8f966e5029bb5518bc99cdb4fcb.1606823325.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 commit back (v6.10.0-5-gb3dad96972) a new helper for obtaining string arrays from a virJSONObject was introduced: virJSONValueObjectGetStringArray(). I've identified three places where it can be used instead of open coding it: qemuAgentSSHGetAuthorizedKeys(), qemuMonitorJSONGetStringListProperty() and qemuMonitorJSONGetCPUDefinitions(). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_agent.c | 30 +++---------------- src/qemu/qemu_monitor_json.c | 56 +++++------------------------------- 2 files changed, 11 insertions(+), 75 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 1796ade6e2..d4530dcd7a 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2533,9 +2533,6 @@ qemuAgentSSHGetAuthorizedKeys(qemuAgentPtr agent, g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; virJSONValuePtr data =3D NULL; - size_t ndata; - size_t i; - char **keys_ret =3D NULL; =20 if (!(cmd =3D qemuAgentMakeCommand("guest-ssh-get-authorized-keys", "s:username", user, @@ -2545,35 +2542,16 @@ qemuAgentSSHGetAuthorizedKeys(qemuAgentPtr agent, if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) return -1; =20 - if (!(data =3D virJSONValueObjectGetObject(reply, "return")) || - !(data =3D virJSONValueObjectGetArray(data, "keys"))) { + if (!(data =3D virJSONValueObjectGetObject(reply, "return"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qemu agent didn't return an array of keys")); return -1; } =20 - ndata =3D virJSONValueArraySize(data); + if (!(*keys =3D virJSONValueObjectGetStringArray(data, "keys"))) + return -1; =20 - keys_ret =3D g_new0(char *, ndata + 1); - - for (i =3D 0; i < ndata; i++) { - virJSONValuePtr entry =3D virJSONValueArrayGet(data, i); - - if (!entry) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("array element missing in guest-ssh-get-autho= rized-keys return value")); - goto error; - } - - keys_ret[i] =3D g_strdup(virJSONValueGetString(entry)); - } - - *keys =3D g_steal_pointer(&keys_ret); - return ndata; - - error: - virStringListFreeCount(keys_ret, ndata); - return -1; + return g_strv_length(*keys); } =20 =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e7aa6b6ffd..ea65d6bee7 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5931,41 +5931,17 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, cpu->type =3D g_strdup(tmp); =20 if (virJSONValueObjectHasKey(child, "unavailable-features")) { - virJSONValuePtr blockers; - size_t j; - size_t len; - - blockers =3D virJSONValueObjectGetArray(child, - "unavailable-features"); - if (!blockers) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("unavailable-features in query-cpu-defini= tions " - "reply data was not an array")); + if (!(cpu->blockers =3D virJSONValueObjectGetStringArray(child, + "unavai= lable-features"))) return -1; - } =20 - len =3D virJSONValueArraySize(blockers); - - if (len =3D=3D 0) { + if (g_strv_length(cpu->blockers) =3D=3D 0) { cpu->usable =3D VIR_DOMCAPS_CPU_USABLE_YES; + g_clear_pointer(&cpu->blockers, g_strfreev); continue; } =20 cpu->usable =3D VIR_DOMCAPS_CPU_USABLE_NO; - cpu->blockers =3D g_new0(char *, len + 1); - - for (j =3D 0; j < len; j++) { - virJSONValuePtr blocker =3D virJSONValueArrayGet(blockers,= j); - - if (virJSONValueGetType(blocker) !=3D VIR_JSON_TYPE_STRING= ) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("unexpected value in unavailable-feat= ures " - "array")); - return -1; - } - - cpu->blockers[j] =3D g_strdup(virJSONValueGetString(blocke= r)); - } } } =20 @@ -6788,9 +6764,6 @@ qemuMonitorJSONGetStringListProperty(qemuMonitorPtr m= on, g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; VIR_AUTOSTRINGLIST list =3D NULL; - virJSONValuePtr data; - size_t n; - size_t i; =20 *strList =3D NULL; =20 @@ -6806,25 +6779,10 @@ qemuMonitorJSONGetStringListProperty(qemuMonitorPtr= mon, if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) return -1; =20 - data =3D virJSONValueObjectGetArray(reply, "return"); - n =3D virJSONValueArraySize(data); + if (!(*strList =3D virJSONValueObjectGetStringArray(reply, "return"))) + return -1; =20 - list =3D g_new0(char *, n + 1); - - for (i =3D 0; i < n; i++) { - virJSONValuePtr item =3D virJSONValueArrayGet(data, i); - - if (virJSONValueGetType(item) !=3D VIR_JSON_TYPE_STRING) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value in %s array"), property); - return -1; - } - - list[i] =3D g_strdup(virJSONValueGetString(item)); - } - - *strList =3D g_steal_pointer(&list); - return n; + return g_strv_length(*strList); } =20 =20 --=20 2.26.2