From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGxAd-0007Ti-JR for qemu-devel@nongnu.org; Fri, 21 Feb 2014 15:58:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGxAV-0001fY-A5 for qemu-devel@nongnu.org; Fri, 21 Feb 2014 15:58:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGxAV-0001fU-21 for qemu-devel@nongnu.org; Fri, 21 Feb 2014 15:57:59 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1LKvwgP017916 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Feb 2014 15:57:58 -0500 Date: Fri, 21 Feb 2014 21:57:55 +0100 From: Kevin Wolf Message-ID: <20140221205755.GD3346@dhcp-200-207.str.redhat.com> References: <1392996248-26781-1-git-send-email-kwolf@redhat.com> <1392996248-26781-2-git-send-email-kwolf@redhat.com> <5307B593.7020801@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="VbJkn9YxBvnuCH5J" Content-Disposition: inline In-Reply-To: <5307B593.7020801@redhat.com> 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: Eric Blake Cc: jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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=3D4k,he= lp' > > are recognised. > >=20 > > is_valid_option_list() ensures that the option list doesn't have options > > with leading commas or trailing unescaped commas. > >=20 > > Signed-off-by: Kevin Wolf > > --- >=20 > > + > > + while (*p) { > > + p =3D get_opt_value(buf, buflen, p); > > + if (*p) { > > + p++; > > + } > > + > > + if (is_help_option(buf)) { > > + result =3D true; > > + goto out; >=20 > If this were 'break;', >=20 > > + } > > + } > > + > > +out: >=20 > then you wouldn't need this label. But that's cosmetic. >=20 > > + free(buf); > > + return result; > > +} > > + > > +bool is_valid_option_list(const char *param) > > +{ > > + size_t buflen =3D strlen(param) + 1; > > + char *buf =3D g_malloc0(buflen); > > + const char *p =3D param; > > + bool result =3D true; > > + > > + while (*p) { > > + p =3D get_opt_value(buf, buflen, p); > > + if (*p && !*++p) { > > + result =3D false; > > + goto out; > > + } >=20 > Rejects trailing commas. >=20 > > + > > + if (!*buf || *buf =3D=3D ',') { >=20 > 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): >=20 > qemu-kvm -machine ,,blah >=20 > as shorthand for >=20 > qemu-kvm -machine type=3D,,blah >=20 > 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. Kevin --VbJkn9YxBvnuCH5J Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJTB73TAAoJEH8JsnLIjy/WMHgP/2ZZWUYGoH3ndjnPjAJZz7cV TIbydHURmeeEQ1Xo49WHg8oIkZ37yokG5bkHXCnLoInFUgh9YPmVB25//gKF4p8K nuV6ocIoyHNgvdvqzuIHvro2QhBSalf9cRLxnACvGKNzg1nm6XN4J5nBKsJgGLus g64VACLVuIhytcH2kdiauQdk6iO2lfFKKJ8VvhdOpClgeKBl5cNmujBkWrL68/iI iqhvtGQpnHzuOGeUhtrDfLNl7aBWcfpHrO0Py0DPAuhZsVizOZ2kBlSIfOK/hj9b yoPlpoiXsPXsCbTj9PW4+Xoe0pnZEF9hdpOLSnxhR8cXkTyAbbt6ez0g09wnepLa UyE5ZLgCmAi24jmueGTkCgJbfyeoCuNeZlTR99n6aN3kwTvpd8kMR+KZT5AabgBY +NsDBWzZ4AW3QiRpyZ9Ae7ECSsiPYkoGPNqmGJiSyT0CgG3aqHk0OAoRgopRIy6E KZQFJcq/ygONWlLVlzAtCrVulkW7C92YTjkmC1Oy+RH2N91Yrt59CZYZ7jDh0UH6 GUEb03T7RrEbL4m3YXOfQPnyFj6TJG02N1+crhv0jeEoxli5xHPdC2os4/KZF3z5 ca2YdekC55Ebcz6ge2/5UnPCyWdY/FfTkwtQ6s9tHNs9CbaxwZJ/Ul/RZSfJebaE NuerKNYst6IKa8qlHIV/ =lHd2 -----END PGP SIGNATURE----- --VbJkn9YxBvnuCH5J--