Skip to content

Commit

Permalink
qapi: Fix crash when 'any' or 'null' parameter is missing
Browse files Browse the repository at this point in the history
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 != !*obj'
failed

Broken in commit 5c678ee.  Fix by adding the missing error checks.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20160922203927.28241-3-marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Commit message rephrased]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
  • Loading branch information
elmarco authored and Markus Armbruster committed Oct 6, 2016
1 parent e64c75a commit c489780
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions qapi/qmp-input-visitor.c
Expand Up @@ -338,6 +338,12 @@ static void qmp_input_type_any(Visitor *v, const char *name, QObject **obj,
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true);

if (!qobj) {
error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null");
*obj = NULL;
return;
}

qobject_incref(qobj);
*obj = qobj;
}
Expand All @@ -347,6 +353,11 @@ static void qmp_input_type_null(Visitor *v, const char *name, Error **errp)
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true);

if (!qobj) {
error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null");
return;
}

if (qobject_type(qobj) != QTYPE_QNULL) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"null");
Expand Down

0 comments on commit c489780

Please sign in to comment.