Received: from eggs.gnu.org ([2001:4830:134:3::10]:51843) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsZh6-0007hO-Vu for qemu-devel@nongnu.org; Fri, 07 Oct 2016 14:16:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsZh3-00019K-Ro for qemu-devel@nongnu.org; Fri, 07 Oct 2016 14:16:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50612) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsZh3-00017o-Hh for qemu-devel@nongnu.org; Fri, 07 Oct 2016 14:16:25 -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 E8116C04B31F for ; Fri, 7 Oct 2016 18:16:24 +0000 (UTC) From: Markus Armbruster Date: Fri, 7 Oct 2016 20:16:13 +0200 Message-Id: <1475864182-16550-3-git-send-email-armbru@redhat.com> In-Reply-To: <1475864182-16550-1-git-send-email-armbru@redhat.com> References: <1475864182-16550-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 v2 02/11] 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