qemu-option: Guard against qemu_opts_set_defaults() misuse
PATCH 1/1 qemu-option: Guard against qemu_opts_set_defaults() misuse
Commit 6d4cd40 fixed qemu_opts_set_defaults() for an existing corner case, but broke it for another one that can't be reached in current code.
Quote from its commit message:
I believe [opts_parse()] 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
The only caller that passes true for defaults isqemu_opts_set_defaults().
The commit message then claims:
A straightforward call of qemu_opts_create() does exactly that.
Wrong. When !list->merge_lists, and the option string doesn't contain id=, and options without ID exist, then we don't actually modify the existing options, we create new ones.
Not reachable, because we never pass lists with !list->merge_lists to qemu_opts_set_defaults().
Guard against possible (if unlikely) future misuse with assert().
--- util/qemu-option.c | 9 +++++++++ 1 file changed, 9 insertions(+)
util/qemu-option.c +9 -0
@@ -928,6 +928,15 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,get_opt_value (value,sizeof (value), p+4 ); id = value; } + +/* +* This code doesn't work for defaults && !list->merge_lists: when +* params has no id=, and list has an element with !opts->id, it +* appends a new element instead of returning the existing opts. +* However, we got no use for this case. Guard against possible +* (if unlikely) future misuse: +*/ +assert (!defaults || list->merge_lists); opts =qemu_opts_create (list, id, !defaults, &local_err);if (opts ==NULL ) {if (error_is_set (&local_err)) {
Signature · 1 line
1.7.11.7
Quoted 17 lines · Markus Armbruster
Commit 6d4cd40 fixed
qemu_opts_set_defaults()for an existing corner case, but broke it for another one that can't be reached in current code.Not reachable, because we never pass lists with !list->merge_lists to
qemu_opts_set_defaults().Guard against possible (if unlikely) future misuse with
assert().Reported-by Peter Maydell <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- util/qemu-option.c | 9 +++++++++ 1 file changed, 9 insertions(+)
util/qemu-option.c static QemuOpts *opts_parse(QemuOptsList *list, const char *params, · line 936
Quoted 4 lines
util/qemu-option.c +4
-0+* This code doesn't work for defaults && !list->merge_lists: when +* params has no id=, and list has an element with !opts->id, it +* appends a new element instead of returning the existing opts. +* However, we got no use for this case. Guard against possible
s/got/have/
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 18 lines · Eric Blake
Quoted 16 lines · Markus Armbruster
Commit 6d4cd40 fixed
qemu_opts_set_defaults()for an existing corner case, but broke it for another one that can't be reached in current code.Not reachable, because we never pass lists with !list->merge_lists to
qemu_opts_set_defaults().Guard against possible (if unlikely) future misuse with
assert().Reported-by Peter Maydell <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- util/qemu-option.c | 9 +++++++++ 1 file changed, 9 insertions(+)
Quoted 6 lines
util/qemu-option.c static QemuOpts *opts_parse(QemuOptsList *list, const char *params, · line 936
Quoted 4 lines
util/qemu-option.c +4
-0+* This code doesn't work for defaults && !list->merge_lists: when +* params has no id=, and list has an element with !opts->id, it +* appends a new element instead of returning the existing opts. +* However, we got no use for this case. Guard against possible s/got/have/
I'd be fine with fixing this on commit.
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Thanks!
Anthony Liguori
AppliedApplied. Thanks.
Regards,
Anthony Liguori