[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 1/6] qemu-option: has_help_option() and is_va
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH v3 1/6] qemu-option: has_help_option() and is_valid_option_list() |
Date: |
Mon, 24 Feb 2014 09:42:11 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
Kevin Wolf <address@hidden> writes:
> Am 21.02.2014 um 21:22 hat Eric Blake geschrieben:
>> On 02/21/2014 08:24 AM, Kevin Wolf wrote:
>> > has_help_option() checks if any help option ('help' or '?') occurs
>> > anywhere in an option string, so that things like 'cluster_size=4k,help'
>> > are recognised.
>> >
>> > is_valid_option_list() ensures that the option list doesn't have options
>> > with leading commas or trailing unescaped commas.
Care to explain why these are bad? I dimly remember Eric and you
discussing it last week, but I sure won't next time I look at this
code...
>> > Signed-off-by: Kevin Wolf <address@hidden>
>> > ---
>>
>> > +
>> > + while (*p) {
>> > + p = get_opt_value(buf, buflen, p);
>> > + if (*p) {
>> > + p++;
>> > + }
>> > +
>> > + if (is_help_option(buf)) {
>> > + result = true;
>> > + goto out;
>>
>> If this were 'break;',
>>
>> > + }
>> > + }
>> > +
>> > +out:
>>
>> then you wouldn't need this label. But that's cosmetic.
>>
>> > + free(buf);
>> > + return result;
>> > +}
>> > +
>> > +bool is_valid_option_list(const char *param)
>> > +{
>> > + size_t buflen = strlen(param) + 1;
>> > + char *buf = g_malloc0(buflen);
>> > + const char *p = param;
>> > + bool result = true;
>> > +
>> > + while (*p) {
>> > + p = get_opt_value(buf, buflen, p);
>> > + if (*p && !*++p) {
>> > + result = false;
>> > + goto out;
>> > + }
>>
>> Rejects trailing commas.
>>
>> > +
>> > + if (!*buf || *buf == ',') {
>>
>> Rejects empty options, but also rejects values beginning with a comma.
>> But we have legacy users that accept implicitly named first options (see
>> opts_do_parse()). For example, this is a valid command line (albeit one
>> that prints a list of valid machines):
>>
>> qemu-kvm -machine ,,blah
>>
>> as shorthand for
>>
>> qemu-kvm -machine type=,,blah
>>
>> and where *buf would indeed be validly ','.
>
> Right, but I can't allow this without allowing '-o ,,' which breaks the
> real use case. So the lesson is that you can concatenate option strings
> and use implicit option names at the same time.
Another wart on the freakishly complex QemuOpts.
[Qemu-devel] [PATCH v3 2/6] qemu-img create: Support multiple -o options, Kevin Wolf, 2014/02/21
[Qemu-devel] [PATCH v3 3/6] qemu-img convert: Support multiple -o options, Kevin Wolf, 2014/02/21
[Qemu-devel] [PATCH v3 4/6] qemu-img amend: Support multiple -o options, Kevin Wolf, 2014/02/21
[Qemu-devel] [PATCH v3 5/6] qemu-img: Allow -o help with incomplete argument list, Kevin Wolf, 2014/02/21
[Qemu-devel] [PATCH v3 6/6] qemu-iotests: Check qemu-img command line parsing, Kevin Wolf, 2014/02/21
Re: [Qemu-devel] [PATCH v3 0/6] qemu-img: Support multiple -o options, Jeff Cody, 2014/02/21