From nobody Sun Feb 8 21:29:01 2026 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=1652196036; cv=none; d=zohomail.com; s=zohoarc; b=Quaks/iAX2PXhqIye6hcuPGu5EHkEfnEiZvDV8omtjuGcPpM5FoCQCHKsNqmx4/Lf3UrL606LM/FZ3o5x7i0MPmgeJyHaaJcBpQL+jylsOfY3KX407DuN+DTaD/WRPwT7gGDsgb8Gk8LHTcXk+jjrg4q3oleM23UkyWRH9uv+U0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652196036; 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=fV1KH0xVj5a6Rwq1IpOwXuJ1l0SmWYVpkl7CFqDWK5c=; b=cS1nHrhH4UovpTfsh6K846Kt9A8zwdsDHtJePSQ61JY/UX/EDQf9aXCWhZYKiBO0EZcjvESIUQlceDmXgWWJxJI4OexTypYRvxNrOYrgnyV+foMDwrZ8GK2XHx0lWNMl6i0wDNS/xl8hSrP6XYrDcH9LdZHgbWK5KDErf+AxZhE= 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 16521960363411003.6054878282133; Tue, 10 May 2022 08:20:36 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-662-YMTmmeXrMV-gvnbFxjyLGg-1; Tue, 10 May 2022 11:20:29 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA7B3185A794; Tue, 10 May 2022 15:20:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97C2314E0435; Tue, 10 May 2022 15:20:23 +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 627811947062; Tue, 10 May 2022 15:20:23 +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 58BF01947063 for ; Tue, 10 May 2022 15:20:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 20F802024CDA; Tue, 10 May 2022 15:20:22 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BB65202699A for ; Tue, 10 May 2022 15:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652196034; 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=fV1KH0xVj5a6Rwq1IpOwXuJ1l0SmWYVpkl7CFqDWK5c=; b=IUBYYba1wBWn2h9sT3wHFf9CgtAaM0MQaT0xqAXW4G/jeF/gqyVt1jrOAXxWJJziV4Yybm owsoIOMgaHC7uhJTOPJ6092IrngijPrvJR/4e4yPT8QmlbgXtx67fUTf2huCe3Ro0Le66m P5jeNRb1y42ZVziIPn9LtRZ8uB40Nto= X-MC-Unique: YMTmmeXrMV-gvnbFxjyLGg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/37] qemuMonitorJSONQueryFdsets: Ensure that JSON arrays are valid before using them Date: Tue, 10 May 2022 17:19:42 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 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 2.85 on 10.11.54.7 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: 1652196038102100010 Content-Type: text/plain; charset="utf-8" The code didn't check that the reply value is an array and that the 'fds' array is present. This could lead to a crash if qemu wouldn't return an array in those places. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 659d957b04..6939eaea17 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -3685,23 +3685,24 @@ qemuMonitorJSONQueryFdsetsParse(virJSONValue *msg, } - fdarray =3D virJSONValueObjectGetArray(entry, "fds"); - fdsetinfo->nfds =3D virJSONValueArraySize(fdarray); - if (fdsetinfo->nfds > 0) - fdsetinfo->fds =3D g_new0(qemuMonitorFdsetFdInfo, fdsetinfo->n= fds); - - for (j =3D 0; j < fdsetinfo->nfds; j++) { - qemuMonitorFdsetFdInfo *fdinfo =3D &fdsetinfo->fds[j]; - virJSONValue *fdentry; - - if (!(fdentry =3D virJSONValueArrayGet(fdarray, j))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-fdsets return data missing fd arra= y element")); - return -1; + if ((fdarray =3D virJSONValueObjectGetArray(entry, "fds"))) { + fdsetinfo->nfds =3D virJSONValueArraySize(fdarray); + if (fdsetinfo->nfds > 0) + fdsetinfo->fds =3D g_new0(qemuMonitorFdsetFdInfo, fdsetinf= o->nfds); + + for (j =3D 0; j < fdsetinfo->nfds; j++) { + qemuMonitorFdsetFdInfo *fdinfo =3D &fdsetinfo->fds[j]; + virJSONValue *fdentry; + + if (!(fdentry =3D virJSONValueArrayGet(fdarray, j))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-fdsets return data missing fd = array element")); + return -1; + } + + /* opaque is optional and may be missing */ + fdinfo->opaque =3D g_strdup(virJSONValueObjectGetString(fd= entry, "opaque")); } - - /* opaque is optional and may be missing */ - fdinfo->opaque =3D g_strdup(virJSONValueObjectGetString(fdentr= y, "opaque")); } } @@ -3723,7 +3724,7 @@ int qemuMonitorJSONQueryFdsets(qemuMonitor *mon, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) return -1; - if (qemuMonitorJSONCheckError(cmd, reply) < 0) + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) return -1; if (qemuMonitorJSONQueryFdsetsParse(reply, fdsets) < 0) --=20 2.35.1