Received: from eggs.gnu.org ([2001:4830:134:3::10]:41907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsTxw-0000Op-1t for qemu-devel@nongnu.org; Fri, 07 Oct 2016 08:09:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsTxp-0006N4-Nh for qemu-devel@nongnu.org; Fri, 07 Oct 2016 08:09:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsTxp-0006Mf-H7 for qemu-devel@nongnu.org; Fri, 07 Oct 2016 08:09:21 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28C2D9D0C8 for ; Fri, 7 Oct 2016 12:09:21 +0000 (UTC) From: Markus Armbruster Date: Fri, 7 Oct 2016 14:09:09 +0200 Message-Id: <1475842159-26039-3-git-send-email-armbru@redhat.com> In-Reply-To: <1475842159-26039-1-git-send-email-armbru@redhat.com> References: <1475842159-26039-1-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 02/12] qapi: Fix crash when 'any' or 'null' parameter is missing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-Andr=C3=A9 Lureau Unlike the other visit methods, visit_type_any() and visit_type_null() neglect to check whether qmp_input_get_object() succeeded. They crash when it fails. Reproducer: { "execute": "qom-set", "arguments": { "path": "/machine", "property": "rtc-time" } } Will crash with: qapi/qapi-visit-core.c:277: visit_type_any: Assertion `!err !=3D !*obj' failed Broken in commit 5c678ee. Fix by adding the missing error checks. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake Message-Id: <20160922203927.28241-3-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster [Commit message rephrased] Signed-off-by: Markus Armbruster --- qapi/qmp-input-visitor.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index 64dd392..fc91e74 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -338,6 +338,12 @@ static void qmp_input_type_any(Visitor *v, const cha= r *name, QObject **obj, QmpInputVisitor *qiv =3D to_qiv(v); QObject *qobj =3D qmp_input_get_object(qiv, name, true); =20 + if (!qobj) { + error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null"); + *obj =3D NULL; + return; + } + qobject_incref(qobj); *obj =3D qobj; } @@ -347,6 +353,11 @@ static void qmp_input_type_null(Visitor *v, const ch= ar *name, Error **errp) QmpInputVisitor *qiv =3D to_qiv(v); QObject *qobj =3D qmp_input_get_object(qiv, name, true); =20 + if (!qobj) { + error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null"); + return; + } + if (qobject_type(qobj) !=3D QTYPE_QNULL) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "nul= l", "null"); --=20 2.5.5