All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>, qemu-devel@nongnu.org
Cc: jcody@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 1/6] qemu-option: has_help_option() and is_valid_option_list()
Date: Fri, 21 Feb 2014 13:22:43 -0700	[thread overview]
Message-ID: <5307B593.7020801@redhat.com> (raw)
In-Reply-To: <1392996248-26781-2-git-send-email-kwolf@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2326 bytes --]

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.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---

> +
> +    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 ','.

> +            result = false;
> +            goto out;
> +        }
> +    }
> +
> +out:

Same observation about the possibility of using break to avoid goto.

> +    free(buf);
> +    return result;
> +}

That said, none of our users of -o options have an implicitly-named
first option, and therefore THIS patch is safe, even if we have a
ticking time-bomb if any other option with implicit first name starts
using this function.  And break vs. goto is cosmetic.  So I'm okay
taking this as-is.

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: 604 bytes --]

  reply	other threads:[~2014-02-21 20:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-21 15:24 [Qemu-devel] [PATCH v3 0/6] qemu-img: Support multiple -o options Kevin Wolf
2014-02-21 15:24 ` [Qemu-devel] [PATCH v3 1/6] qemu-option: has_help_option() and is_valid_option_list() Kevin Wolf
2014-02-21 20:22   ` Eric Blake [this message]
2014-02-21 20:57     ` Kevin Wolf
2014-02-24  8:42       ` Markus Armbruster
2014-02-24  9:42         ` Kevin Wolf
2014-02-21 15:24 ` [Qemu-devel] [PATCH v3 2/6] qemu-img create: Support multiple -o options Kevin Wolf
2014-02-21 15:24 ` [Qemu-devel] [PATCH v3 3/6] qemu-img convert: " Kevin Wolf
2014-03-03 11:43   ` Peter Lieven
2014-03-03 13:08     ` Kevin Wolf
2014-02-21 15:24 ` [Qemu-devel] [PATCH v3 4/6] qemu-img amend: " Kevin Wolf
2014-02-21 15:24 ` [Qemu-devel] [PATCH v3 5/6] qemu-img: Allow -o help with incomplete argument list Kevin Wolf
2014-02-21 15:24 ` [Qemu-devel] [PATCH v3 6/6] qemu-iotests: Check qemu-img command line parsing Kevin Wolf
2014-02-21 20:38   ` Eric Blake
2014-02-21 19:59 ` [Qemu-devel] [PATCH v3 0/6] qemu-img: Support multiple -o options Jeff Cody

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5307B593.7020801@redhat.com \
    --to=eblake@redhat.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.