From nobody Fri May 17 12:14:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522334179738713.0960364982069; Thu, 29 Mar 2018 07:36:19 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 69B1D51F0B; Thu, 29 Mar 2018 14:36:17 +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 3188F620D7; Thu, 29 Mar 2018 14:36:16 +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 8AE89181BA04; Thu, 29 Mar 2018 14:36:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2TEaBF6022764 for ; Thu, 29 Mar 2018 10:36:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 625B010B2B46; Thu, 29 Mar 2018 14:36:11 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0993210B2B44 for ; Thu, 29 Mar 2018 14:36:08 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id BE0E0103A81; Thu, 29 Mar 2018 16:36:07 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Thu, 29 Mar 2018 16:35:59 +0200 Message-Id: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu_monitor_json: Properly check "return" type 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Mar 2018 14:36:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" My commit 2e0d6cdec41 claimed qemuMonitorJSONCheckError guarantees "return" object exists in the JSON reply. But it only makes sure the key is there, while the type of the value is not checked. A lot of callers do not care since they only want to see whether their QMP command failed or not, but any caller which needs to read some data from the reply wants to make sure the correct data type was returned. This patch adds a new API called qemuMonitorJSONCheckReply which calls qemuMonitorJSONCheckError and checks "return" contains a value of the specified type. Signed-off-by: Jiri Denemark --- src/qemu/qemu_monitor_json.c | 261 ++++++++++++++++++---------------------= ---- 1 file changed, 108 insertions(+), 153 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d80c4f18d1..b251fc9964 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -413,6 +413,36 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd, } =20 =20 +static int +qemuMonitorJSONCheckReply(virJSONValuePtr cmd, + virJSONValuePtr reply, + virJSONType type) +{ + virJSONValuePtr data; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + return -1; + + data =3D virJSONValueObjectGet(reply, "return"); + if (data->type !=3D type) { + char *cmdstr =3D virJSONValueToString(cmd, false); + char *retstr =3D virJSONValueToString(data, false); + + VIR_DEBUG("Unexpected return type %d (expecting %d) for command %s= : %s", + data->type, type, cmdstr, retstr); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected type returned by QEMU command '%s'"), + qemuMonitorJSONCommandName(cmd)); + + VIR_FREE(cmdstr); + VIR_FREE(retstr); + return -1; + } + + return 0; +} + + static bool qemuMonitorJSONErrorIsClass(virJSONValuePtr error, const char *klass) @@ -1389,7 +1419,7 @@ qemuMonitorJSONGetStatus(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 data =3D virJSONValueObjectGetObject(reply, "return"); @@ -1616,7 +1646,7 @@ int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 data =3D virJSONValueObjectGetObject(reply, "return"); @@ -1777,7 +1807,7 @@ qemuMonitorJSONGetBalloonInfo(qemuMonitorPtr mon, } =20 /* See if any other fatal error occurred */ - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 data =3D virJSONValueObjectGetObject(reply, "return"); @@ -1878,7 +1908,7 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon, } } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 data =3D virJSONValueObjectGetObject(reply, "return"); @@ -1956,14 +1986,10 @@ qemuMonitorJSONQueryBlock(qemuMonitorPtr mon) return NULL; =20 if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0 || - qemuMonitorJSONCheckError(cmd, reply) < 0) + qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(devices =3D virJSONValueObjectStealArray(reply, "return"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-block reply was missing device list")); - goto cleanup; - } + devices =3D virJSONValueObjectStealArray(reply, "return"); =20 cleanup: virJSONValueFree(cmd); @@ -2163,14 +2189,10 @@ qemuMonitorJSONQueryBlockstats(qemuMonitorPtr mon) if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(ret =3D virJSONValueObjectStealArray(reply, "return"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-blockstats reply was missing device list")= ); - goto cleanup; - } + ret =3D virJSONValueObjectStealArray(reply, "return"); =20 cleanup: virJSONValueFree(cmd); @@ -2705,13 +2727,12 @@ qemuMonitorJSONGetMigrationCacheSize(qemuMonitorPtr= mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_NUMBER) < 0) goto cleanup; =20 if (virJSONValueObjectGetNumberUlong(reply, "return", cacheSize) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-migrate-cache-size reply was missing " - "'return' data")); + _("invalid cache size in query-migrate-cache-size r= eply")); goto cleanup; } =20 @@ -2773,7 +2794,7 @@ qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 result =3D virJSONValueObjectGet(reply, "return"); @@ -3133,7 +3154,7 @@ int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr m= on, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 if (qemuMonitorJSONGetMigrationStatsReply(reply, stats, error) < 0) @@ -3225,7 +3246,7 @@ qemuMonitorJSONQueryDump(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 result =3D virJSONValueObjectGetObject(reply, "return"); @@ -3262,7 +3283,7 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonit= orPtr mon, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 caps =3D virJSONValueObjectGetObject(reply, "return"); @@ -3434,7 +3455,7 @@ qemuMonitorJSONAddFd(qemuMonitorPtr mon, int fdset, i= nt fd, const char *name) ret =3D -2; goto cleanup; } - ret =3D qemuMonitorJSONCheckError(cmd, reply); + ret =3D qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT= ); } if (ret =3D=3D 0) { virJSONValuePtr data =3D virJSONValueObjectGetObject(reply, "retur= n"); @@ -3561,11 +3582,8 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr ms= g, if (!fil) goto cleanup; =20 - if (!(returnArray =3D virJSONValueObjectGetArray(msg, "return"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-rx-filter reply was missing return data")); - goto cleanup; - } + returnArray =3D virJSONValueObjectGetArray(msg, "return"); + if (!(entry =3D virJSONValueArrayGet(returnArray, 0))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query -rx-filter return data missing array eleme= nt")); @@ -3739,7 +3757,7 @@ qemuMonitorJSONQueryRxFilter(qemuMonitorPtr mon, cons= t char *alias, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 if (qemuMonitorJSONQueryRxFilterParse(reply, filter) < 0) @@ -3776,11 +3794,7 @@ qemuMonitorJSONExtractChardevInfo(virJSONValuePtr re= ply, size_t i; qemuMonitorChardevInfoPtr entry =3D NULL; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("character device reply was missing return data")= ); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); =20 for (i =3D 0; i < virJSONValueArraySize(data); i++) { virJSONValuePtr chardev =3D virJSONValueArrayGet(data, i); @@ -3857,7 +3871,7 @@ qemuMonitorJSONGetChardevInfo(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 ret =3D qemuMonitorJSONExtractChardevInfo(reply, info); @@ -5035,7 +5049,7 @@ int qemuMonitorJSONGetVersion(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 data =3D virJSONValueObjectGetObject(reply, "return"); @@ -5101,15 +5115,11 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-machines reply data was not an array")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 /* null-terminated list */ if (VIR_ALLOC_N(infolist, n + 1) < 0) @@ -5206,15 +5216,11 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-cpu-definitions reply data was not an arra= y")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 if (VIR_ALLOC_N(cpulist, n) < 0) goto cleanup; @@ -5411,7 +5417,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mo= n, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 data =3D virJSONValueObjectGetObject(reply, "return"); @@ -5494,15 +5500,11 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-commands reply data was not an array")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 /* null-terminated list */ if (VIR_ALLOC_N(commandlist, n + 1) < 0) @@ -5559,15 +5561,11 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-events reply data was not an array")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 /* null-terminated list */ if (VIR_ALLOC_N(eventlist, n + 1) < 0) @@ -5744,7 +5742,7 @@ int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 data =3D virJSONValueObjectGetObject(reply, "return"); @@ -5784,15 +5782,11 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mo= n, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("qom-list-types reply data was not an array")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 /* null-terminated list */ if (VIR_ALLOC_N(typelist, n + 1) < 0) @@ -5846,15 +5840,11 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPt= r mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("qom-list reply data was not an array")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 /* null-terminated list */ if (VIR_ALLOC_N(pathlist, n + 1) < 0) @@ -6085,15 +6075,11 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mo= n, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("device-list-properties reply data was not an arr= ay")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 /* null-terminated list */ if (VIR_ALLOC_N(proplist, n + 1) < 0) @@ -6140,7 +6126,7 @@ qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon) if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 data =3D virJSONValueObjectGetObject(reply, "return"); @@ -6186,15 +6172,11 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitor= Ptr mon, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(caps =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(caps)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing migration capabilities")); - goto cleanup; - } + caps =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(caps); =20 if (VIR_ALLOC_N(list, n + 1) < 0) goto cleanup; @@ -6330,15 +6312,11 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mo= n, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(caps =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(caps)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing GIC capabilities")); - goto cleanup; - } + caps =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(caps); =20 /* If the returned array was empty we have to return successfully */ if (n =3D=3D 0) { @@ -6555,16 +6533,11 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, c= onst char *qmpCmd, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("%s reply data was not an array"), - qmpCmd); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 /* null-terminated list */ if (VIR_ALLOC_N(list, n + 1) < 0) @@ -6792,8 +6765,13 @@ qemuMonitorJSONAttachCharDev(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + if (chr->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY) { + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < = 0) + goto cleanup; + } else { + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + } =20 if (chr->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY) { virJSONValuePtr data =3D virJSONValueObjectGetObject(reply, "retur= n"); @@ -6939,11 +6917,7 @@ qemuMonitorJSONParseCPUx86Features(virJSONValuePtr d= ata) size_t i; ssize_t n; =20 - if (!data || (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid array of CPUID features")); - goto error; - } + n =3D virJSONValueArraySize(data); =20 if (!(cpudata =3D virCPUDataNew(VIR_ARCH_X86_64))) goto error; @@ -6982,7 +6956,7 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply)) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 data =3D virJSONValueObjectGetArray(reply, "return"); @@ -7029,15 +7003,11 @@ qemuMonitorJSONCheckCPUx86(qemuMonitorPtr mon) } } =20 - if (qemuMonitorJSONCheckError(cmd, reply)) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("qom-list reply data was not an array")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 for (i =3D 0; i < n; i++) { virJSONValuePtr element =3D virJSONValueArrayGet(data, i); @@ -7162,15 +7132,11 @@ qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-iothreads reply data was not an array")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 /* null-terminated list */ if (VIR_ALLOC_N(infolist, n + 1) < 0) @@ -7251,15 +7217,11 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr m= on, goto cleanup; } =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(data =3D virJSONValueObjectGetArray(reply, "return")) || - (n =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-memory-devices reply data was not an array= ")); - goto cleanup; - } + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); =20 for (i =3D 0; i < n; i++) { virJSONValuePtr elem =3D virJSONValueArrayGet(data, i); @@ -7582,7 +7544,7 @@ qemuMonitorJSONGetRTCTime(qemuMonitorPtr mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) goto cleanup; =20 data =3D virJSONValueObjectGet(reply, "return"); @@ -7741,16 +7703,11 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr m= on, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 data =3D virJSONValueObjectGet(reply, "return"); - - if ((ninfo =3D virJSONValueArraySize(data)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-hotpluggable-cpus reply is not an array")); - goto cleanup; - } + ninfo =3D virJSONValueArraySize(data); =20 if (VIR_ALLOC_N(info, ninfo) < 0) goto cleanup; @@ -7789,12 +7746,10 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon) if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 - if (!(ret =3D virJSONValueObjectStealArray(reply, "return"))) - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-qmp-schema reply is not an array")); + ret =3D virJSONValueObjectStealArray(reply, "return"); =20 cleanup: virJSONValueFree(cmd); @@ -7848,7 +7803,7 @@ qemuMonitorJSONQueryNamedBlockNodes(qemuMonitorPtr mo= n) if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; =20 - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) goto cleanup; =20 ret =3D virJSONValueObjectStealArray(reply, "return"); --=20 2.16.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list