* [Qemu-devel] [PATCH] qemu-option: Guard against qemu_opts_set_defaults() misuse
@ 2013-08-02 7:34 Markus Armbruster
2013-08-02 13:37 ` Eric Blake
2013-08-14 16:28 ` Anthony Liguori
0 siblings, 2 replies; 4+ messages in thread
From: Markus Armbruster @ 2013-08-02 7:34 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, aliguori
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 is
qemu_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().
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
util/qemu-option.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 7a1552a..4ebdc4c 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -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)) {
--
1.7.11.7
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-option: Guard against qemu_opts_set_defaults() misuse
2013-08-02 7:34 [Qemu-devel] [PATCH] qemu-option: Guard against qemu_opts_set_defaults() misuse Markus Armbruster
@ 2013-08-02 13:37 ` Eric Blake
2013-08-02 16:51 ` Markus Armbruster
2013-08-14 16:28 ` Anthony Liguori
1 sibling, 1 reply; 4+ messages in thread
From: Eric Blake @ 2013-08-02 13:37 UTC (permalink / raw)
To: Markus Armbruster; +Cc: peter.maydell, aliguori, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]
On 08/02/2013 01:34 AM, Markus Armbruster wrote:
> 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 <peter.maydell@linaro.org>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> util/qemu-option.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
> + * 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/
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-option: Guard against qemu_opts_set_defaults() misuse
2013-08-02 13:37 ` Eric Blake
@ 2013-08-02 16:51 ` Markus Armbruster
0 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2013-08-02 16:51 UTC (permalink / raw)
To: Eric Blake; +Cc: peter.maydell, aliguori, qemu-devel
Eric Blake <eblake@redhat.com> writes:
> On 08/02/2013 01:34 AM, Markus Armbruster wrote:
>> 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 <peter.maydell@linaro.org>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>> util/qemu-option.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>
>> + * 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.
> Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-option: Guard against qemu_opts_set_defaults() misuse
2013-08-02 7:34 [Qemu-devel] [PATCH] qemu-option: Guard against qemu_opts_set_defaults() misuse Markus Armbruster
2013-08-02 13:37 ` Eric Blake
@ 2013-08-14 16:28 ` Anthony Liguori
1 sibling, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2013-08-14 16:28 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: peter.maydell, aliguori
Applied. Thanks.
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-08-14 16:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-02 7:34 [Qemu-devel] [PATCH] qemu-option: Guard against qemu_opts_set_defaults() misuse Markus Armbruster
2013-08-02 13:37 ` Eric Blake
2013-08-02 16:51 ` Markus Armbruster
2013-08-14 16:28 ` Anthony Liguori
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.