Skip to content

Commit

Permalink
qom: Avoid unvisited 'id'/'qom-type' in user_creatable_add_opts
Browse files Browse the repository at this point in the history
A regression in commit 15c2f66 caused us to silently ignore
excess input to the QemuOpts visitor.  Later, commit ea4641
accidentally abused that situation, by removing "qom-type" and
"id" from the corresponding QDict but leaving them defined in
the QemuOpts, when using the pair of containers to create a
user-defined object. Note that since we are already traversing
two separate items (a QDict and a QemuOpts), we are already
able to flag bogus arguments, as in:

$ ./x86_64-softmmu/qemu-system-x86_64 -nodefaults -nographic -qmp stdio -object memory-backend-ram,id=mem1,size=4k,bogus=huh
qemu-system-x86_64: -object memory-backend-ram,id=mem1,size=4k,bogus=huh: Property '.bogus' not found

So the only real concern is that when we re-enable strict checking
in the QemuOpts visitor, we do not want to start flagging the two
leftover keys as unvisited.  Rearrange the code to clean out the
QemuOpts listing in advance, rather than removing items from the
QDict.  Since "qom-type" is usually an automatic implicit default,
we don't have to restore it (this does mean that once instantiated,
QemuOpts is not necessarily an accurate representation of the
original command line - but this is not the first place to do that);
however "id" has to be put back (requiring us to cast away a const).

[As a side note, hmp_object_add() turns a QDict into a QemuOpts,
then calls user_creatable_add_opts() which converts QemuOpts into
a new QDict. There are probably a lot of wasteful conversions like
this, but cleaning them up is a much bigger task than the immediate
regression fix.]

CC: qemu-stable@nongnu.org
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20170322144525.18964-3-eblake@redhat.com>
Tested-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
(cherry picked from commit 9a6d1ac)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
(cherry picked from commit 7967e0bd9d8c4d7aae11383f9d9bad2ceaf9c2a2)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
ebblake authored and mdroth committed Mar 30, 2017
1 parent dd39c54 commit c15c6d2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions qom/object_interfaces.c
Expand Up @@ -109,25 +109,27 @@ Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
QDict *pdict;
Object *obj;
const char *id = qemu_opts_id(opts);
const char *type = qemu_opt_get(opts, "qom-type");
char *type = qemu_opt_get_del(opts, "qom-type");

if (!type) {
error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
return NULL;
}
if (!id) {
error_setg(errp, QERR_MISSING_PARAMETER, "id");
g_free(type);
return NULL;
}

qemu_opts_set_id(opts, NULL);
pdict = qemu_opts_to_qdict(opts, NULL);
qdict_del(pdict, "qom-type");
qdict_del(pdict, "id");

v = opts_visitor_new(opts);
obj = user_creatable_add_type(type, id, pdict, v, errp);
visit_free(v);

qemu_opts_set_id(opts, (char *) id);
g_free(type);
QDECREF(pdict);
return obj;
}
Expand Down

0 comments on commit c15c6d2

Please sign in to comment.