qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] rewamp/simplify option parsing
Date: Mon, 12 May 2014 10:26:59 -0600	[thread overview]
Message-ID: <5370F653.6060305@redhat.com> (raw)
In-Reply-To: <1399881324-14859-1-git-send-email-mjt@msgid.tls.msk.ru>

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

On 05/12/2014 01:55 AM, Michael Tokarev wrote:

s/rewamp/revamp/ in the subject

> Main change is to allow get_opt_name() to accept
> a set of delimiters (string) instead of a single
> delimiter (char).  This way it is easier to search
> for the next (sub)option in an option string, so
> other code using get_opt_name() can be simplified.
> 
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> This is an old patch (from Jun 2013) which was
> sitting in my local git repository since that.
> I rebased it to current master (with 2 trivial
> conflicts resolved).
> 
> FWIW.
> 
>  include/qemu/option.h |    3 +-
>  util/qemu-option.c    |  136 +++++++++++++++++++++++--------------------------
>  vl.c                  |    4 +-
>  3 files changed, 67 insertions(+), 76 deletions(-)
> 

> @@ -97,24 +95,27 @@ int get_next_param_value(char *buf, int buf_size,
>  
>      p = *pstr;
>      for(;;) {
> -        p = get_opt_name(option, sizeof(option), p, '=');
> -        if (*p != '=')
> -            break;
> -        p++;
> -        if (!strcmp(tag, option)) {
> -            *pstr = get_opt_value(buf, buf_size, p);
> -            if (**pstr == ',') {
> -                (*pstr)++;
> +        if (*p == '\0') {
> +            return 0;
> +        }
> +        p = get_opt_name(option, sizeof(option), p, "=,");
> +        if (strcmp(tag, option) == 0) {
> +            if (*p == '=') {
> +                p = get_opt_value(buf, buf_size, p + 1);
> +            } else {
> +                buf[0] = '\0';
>              }
> -            return strlen(buf);
> +            *pstr = *p == ',' ? p + 1 : p;
> +            return 1;

Does this botch handling of ',,' escaping that allows literal commas as
part of an option value?  I suspect there may be some corner cases you
are altering.  Based just on a quick read of 'qemu-kvm -help', I see:

-name string1[,process=string2][,debug-threads=on|off]

Which, if I'm interpreting correctly, means that pre-patch I can do:

qemu-kvm -name foo,,bar /dev/null

as a way to start a (pretty pointless) machine with the window title of
"QEMU (foo,bar)".  Reading the source code, I also found the implicit
name of string1:

qemu-kvm -name guest=debug-threads= /dev/null

creates the window title "QEMU (debug-threads=)", and:

qemu-kvm -name debug-threads,, /dev/null

creates the window title "QEMU (debug-threads,)".  That is, I have a way
of specifying ANY name, including trailing '=' or ',', for my guest.

I did not apply your patch, but off-hand, I'm guessing that your patch
breaks at least one, if not multiple, of these cases.  We need unit
tests in place first.

-- 
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-05-12 16:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-12  7:55 [Qemu-devel] [PATCH] rewamp/simplify option parsing Michael Tokarev
2014-05-12 16:26 ` Eric Blake [this message]

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=5370F653.6060305@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).