OSDN Git Service

qemu-option: Fix qemu_opts_set_defaults() for corner cases
authorMarkus Armbruster <armbru@redhat.com>
Thu, 4 Jul 2013 13:09:18 +0000 (15:09 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 9 Jul 2013 18:38:57 +0000 (13:38 -0500)
commit6d4cd408686f5ae60b2b3b94b79f48ddedc2f39d
treeb11c2df809eba53d98265e234aac39045fff5fb7
parent96bc97ebf350ec480b69082819cedb8850f46a0f
qemu-option: Fix qemu_opts_set_defaults() for corner cases

Commit 4f6dd9a changed the initialization of opts in opts_parse() to
this:

    if (defaults) {
        if (!id && !QTAILQ_EMPTY(&list->head)) {
            opts = qemu_opts_find(list, NULL);
        } else {
            opts = qemu_opts_create(list, id, 0);
        }
    } else {
        opts = qemu_opts_create(list, id, 1);
    }

Same as before for !defaults.

If defaults is true, and params has no ID, and options exist, we use
the first assignment.  It sets opts to null if all options have an ID.
opts_parse() then returns null.  qemu_opts_set_defaults() asserts the
value is non-null.  It's the only caller that passes true for
defaults.

To reproduce, try "-M xenpv -machine id=foo" (yes, "id=foo" is silly,
but it shouldn't crash).

I believe the function attempts to do the following:

    If options don't yet exist, create new options
    Else, if defaults, modify the existing options
    Else, if list->merge_lists, modify the existing options
    Else, fail

A straightforward call of qemu_opts_create() does exactly that.

Cc: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-id: 1372943363-24081-3-git-send-email-armbru@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
util/qemu-option.c