From nobody Fri Apr 26 06:03:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1487072505840704.9153545493582; Tue, 14 Feb 2017 03:41:45 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1EBcDGc037482; Tue, 14 Feb 2017 06:38:13 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1EBcBit027643 for ; Tue, 14 Feb 2017 06:38:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2B0D96D230; Tue, 14 Feb 2017 11:38:11 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F2F8C6D242 for ; Tue, 14 Feb 2017 11:38:10 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 8CE0F1000E7; Tue, 14 Feb 2017 12:38:09 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 14 Feb 2017 12:38:07 +0100 Message-Id: <4a5f21310ea9e2b6bbf8e6bb040b360ec45c17d9.1487072287.git.jdenemar@redhat.com> Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu_monitor_json: Properly check GetArray return value 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Commit 2a8d40f4ec refactored qemuMonitorJSONGetCPUx86Data and replaced virJSONValueObjectGet(reply, "return") with virJSONValueObjectGetArray. While the former is guaranteed to always return non-NULL pointer the latter may return NULL if the returned JSON object is not an array. Signed-off-by: Jiri Denemark --- src/qemu/qemu_monitor_json.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e30b72cd4..1d281af48 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6554,7 +6554,7 @@ qemuMonitorJSONParseCPUx86Features(virJSONValuePtr da= ta, ssize_t n; int ret =3D -1; =20 - if ((n =3D virJSONValueArraySize(data)) < 0) { + if (!data || (n =3D virJSONValueArraySize(data)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid array of CPUID features")); return -1; @@ -6644,9 +6644,8 @@ qemuMonitorJSONCheckCPUx86(qemuMonitorPtr mon) if (qemuMonitorJSONCheckError(cmd, reply)) goto cleanup; =20 - data =3D virJSONValueObjectGetArray(reply, "return"); - - if ((n =3D virJSONValueArraySize(data)) < 0) { + 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; --=20 2.11.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list