diff options
author | Markus Armbruster <armbru@redhat.com> | 2015-10-15 16:15:34 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-10-29 14:34:45 +0100 |
commit | 89cad9f3ec6b30d7550fb5704475fc9c3393a066 (patch) | |
tree | 8dc83797bad950cc5fc6f69215032cd2b120840e /qga/main.c | |
parent | 14b6160099f0caf5dc9d62e637b007bc5d719a96 (diff) |
qdict: Make conversion from QObject * accept null
qobject_to_qdict() crashes on null, which is a trap for the unwary.
Return null instead, and simplify a few callers.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1444918537-18107-4-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'qga/main.c')
-rw-r--r-- | qga/main.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/qga/main.c b/qga/main.c index 068169fcbc..d2a0ffc807 100644 --- a/qga/main.c +++ b/qga/main.c @@ -573,7 +573,6 @@ static void process_command(GAState *s, QDict *req) static void process_event(JSONMessageParser *parser, QList *tokens) { GAState *s = container_of(parser, GAState, parser); - QObject *obj; QDict *qdict; Error *err = NULL; int ret; @@ -581,9 +580,9 @@ static void process_event(JSONMessageParser *parser, QList *tokens) g_assert(s && parser); g_debug("process_event: called"); - obj = json_parser_parse_err(tokens, NULL, &err); - if (err || !obj || qobject_type(obj) != QTYPE_QDICT) { - qobject_decref(obj); + qdict = qobject_to_qdict(json_parser_parse_err(tokens, NULL, &err)); + if (err || !qdict) { + QDECREF(qdict); qdict = qdict_new(); if (!err) { g_warning("failed to parse event: unknown error"); @@ -593,12 +592,8 @@ static void process_event(JSONMessageParser *parser, QList *tokens) } qdict_put_obj(qdict, "error", qmp_build_error_object(err)); error_free(err); - } else { - qdict = qobject_to_qdict(obj); } - g_assert(qdict); - /* handle host->guest commands */ if (qdict_haskey(qdict, "execute")) { process_command(s, qdict); |