From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGwcV-0002FK-V1 for qemu-devel@nongnu.org; Fri, 21 Feb 2014 15:22:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGwcR-0006qZ-1Q for qemu-devel@nongnu.org; Fri, 21 Feb 2014 15:22:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:21603) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGwcQ-0006qQ-PE for qemu-devel@nongnu.org; Fri, 21 Feb 2014 15:22:46 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1LKMjaN003798 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Feb 2014 15:22:45 -0500 Message-ID: <5307B593.7020801@redhat.com> Date: Fri, 21 Feb 2014 13:22:43 -0700 From: Eric Blake MIME-Version: 1.0 References: <1392996248-26781-1-git-send-email-kwolf@redhat.com> <1392996248-26781-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1392996248-26781-2-git-send-email-kwolf@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="D1Lqf4ak98nu5N6U9p3osMoHdvHtcWPUC" 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 , qemu-devel@nongnu.org Cc: jcody@redhat.com, stefanha@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --D1Lqf4ak98nu5N6U9p3osMoHdvHtcWPUC Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 option= s > with leading commas or trailing unescaped commas. >=20 > Signed-off-by: Kevin Wolf > --- > + > + while (*p) { > + p =3D get_opt_value(buf, buflen, p); > + if (*p) { > + p++; > + } > + > + if (is_help_option(buf)) { > + result =3D 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 =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; > + } Rejects trailing commas. > + > + if (!*buf || *buf =3D=3D ',') { 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=3D,,blah and where *buf would indeed be validly ','. > + result =3D 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 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --D1Lqf4ak98nu5N6U9p3osMoHdvHtcWPUC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJTB7WTAAoJEKeha0olJ0NqrJYH/0htJZMkt4G+flqX+ZZP8DKX Uye9j8Cv1ycrWLxwH+K8Uzh/enrK00KU+ttiwl4GlRsZXrfdC+RwZiO3C3kf9/Rk CO2hdqUwzOyZnTjaNvDa9VjAffFRfZUvo9rllB4t+UNkQLBoXWAbTDMhBDFp3LHn aERXo50fER2KSsvJt83PU1paFHoMAlifIbrej0uCSrxhwy7uIy5b5mNdd6Dtm2lq jeTGjVVKXEQJxu6f5ruzKCgTW64rTDKmmEO9WUdA9OHCKGCOp4wYjS1SXJLv0I+I /cT1GOEa4nUucKG1l40FTEsfRO+G5A0gp3nIDuLTstOWpPsmfTgcBMNNqZl3CJU= =229w -----END PGP SIGNATURE----- --D1Lqf4ak98nu5N6U9p3osMoHdvHtcWPUC--