Received: from eggs.gnu.org ([2001:4830:134:3::10]:56493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WHsRQ-0007Fz-64 for qemu-devel@nongnu.org; Mon, 24 Feb 2014 05:07:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WHsRK-0004OB-0y for qemu-devel@nongnu.org; Mon, 24 Feb 2014 05:07:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36869) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WHsRJ-0004O1-NT for qemu-devel@nongnu.org; Mon, 24 Feb 2014 05:07:09 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1OA6iGO002384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 24 Feb 2014 05:07:09 -0500 From: Markus Armbruster References: <1392996248-26781-1-git-send-email-kwolf@redhat.com> <1392996248-26781-2-git-send-email-kwolf@redhat.com> <5307B593.7020801@redhat.com> <20140221205755.GD3346@dhcp-200-207.str.redhat.com> Date: Mon, 24 Feb 2014 09:42:11 +0100 In-Reply-To: <20140221205755.GD3346@dhcp-200-207.str.redhat.com> (Kevin Wolf's message of "Fri, 21 Feb 2014 21:57:55 +0100") Message-ID: <87bnxw6gws.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v3 1/6] qemu-option: has_help_option() and is_valid_option_list() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Kevin Wolf 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 >> > --- >> >> > + >> > + 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.