From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:43569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rbawn-0001Hj-8A for qemu-devel@nongnu.org; Fri, 16 Dec 2011 11:47:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rbawk-0004ke-Af for qemu-devel@nongnu.org; Fri, 16 Dec 2011 11:47:49 -0500 Received: from mail-gy0-f173.google.com ([209.85.160.173]:52990) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rbawk-0004kY-74 for qemu-devel@nongnu.org; Fri, 16 Dec 2011 11:47:46 -0500 Received: by ghbg19 with SMTP id g19so2931952ghb.4 for ; Fri, 16 Dec 2011 08:47:45 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 16 Dec 2011 17:47:26 +0100 Message-Id: <1324054053-20484-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1324054053-20484-1-git-send-email-pbonzini@redhat.com> References: <1324054053-20484-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v2 1/8] qapi: protect against NULL QObject in qmp_input_get_object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org A NULL qobj can occur when a parameter is fetched via qdict_get, but the parameter is not in the command. By returning NULL, the caller can choose whether to raise a missing parameter error, an invalid parameter type error, or use a default value. For example, qom-set could can use this to reset a property to its default value, though at this time it will fail with "Invalid parameter type". In any case, anything is better than crashing! Reviewed-by: Anthony Liguori Signed-off-by: Paolo Bonzini --- qapi/qmp-input-visitor.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index 8cbc0ab..c78022b 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -49,10 +49,12 @@ static const QObject *qmp_input_get_object(QmpInputVisitor *qiv, qobj = qiv->stack[qiv->nb_stack - 1].obj; } - if (name && qobject_type(qobj) == QTYPE_QDICT) { - return qdict_get(qobject_to_qdict(qobj), name); - } else if (qiv->nb_stack > 0 && qobject_type(qobj) == QTYPE_QLIST) { - return qlist_entry_obj(qiv->stack[qiv->nb_stack - 1].entry); + if (qobj) { + if (name && qobject_type(qobj) == QTYPE_QDICT) { + return qdict_get(qobject_to_qdict(qobj), name); + } else if (qiv->nb_stack > 0 && qobject_type(qobj) == QTYPE_QLIST) { + return qlist_entry_obj(qiv->stack[qiv->nb_stack - 1].entry); + } } return qobj; -- 1.7.7.1