From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yfz0U-0005yd-VT for qemu-devel@nongnu.org; Wed, 08 Apr 2015 19:03:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yfz0P-00032J-T5 for qemu-devel@nongnu.org; Wed, 08 Apr 2015 19:03:38 -0400 Received: from resqmta-po-01v.sys.comcast.net ([96.114.154.160]:55762) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yfz0P-00032F-MU for qemu-devel@nongnu.org; Wed, 08 Apr 2015 19:03:33 -0400 Message-ID: <5525B3B8.40709@redhat.com> Date: Wed, 08 Apr 2015 17:03:20 -0600 From: Eric Blake MIME-Version: 1.0 References: <1428516988-6760-1-git-send-email-ehabkost@redhat.com> In-Reply-To: <1428516988-6760-1-git-send-email-ehabkost@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="hfdhSgO8BvkFrfwx6lMOt9QbnQbOEprGQ" Subject: Re: [Qemu-devel] [PATCH] qemu-config: Accept empty option values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost , qemu-devel@nongnu.org Cc: Paolo Bonzini , Gerd Hoffmann This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --hfdhSgO8BvkFrfwx6lMOt9QbnQbOEprGQ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 04/08/2015 12:16 PM, Eduardo Habkost wrote: > Currently it is impossible to set an option in a config file to an empt= y > string, because the parser matches only lines containing non-empty > strings between double-quotes. >=20 > As sscanf() "[" conversion specifier only matches non-empty strings, ad= d > a special case for empty strings. I avoid sscanf() as a rule (as it's behavior on %d is undefined in the face of malicious input), so I had to read the man page; but you are right. Libvirt is trying to completely ban use of *scanf for that reason; but obviously qemu is not quite so opposed to it. >=20 > Signed-off-by: Eduardo Habkost > --- > util/qemu-config.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) >=20 > diff --git a/util/qemu-config.c b/util/qemu-config.c > index 2d32ce7..9f9577d 100644 > --- a/util/qemu-config.c > +++ b/util/qemu-config.c > @@ -413,7 +413,8 @@ int qemu_config_parse(FILE *fp, QemuOptsList **list= s, const char *fname) > opts =3D qemu_opts_create(list, NULL, 0, &error_abort); > continue; > } > - if (sscanf(line, " %63s =3D \"%1023[^\"]\"", arg, value) =3D=3D= 2) { > + if (sscanf(line, " %63s =3D \"%1023[^\"]\"", arg, value) =3D=3D= 2 || > + (value[0] =3D '\0', sscanf(line, " %63s =3D \"\"", arg) =3D= =3D 1)) { This is one of the few times I've seen sscanf used in a well-defined manner (albeit still arbitrarily limiting, in that we have fixed-size buffers) - but having to rely on a comma operator to get there makes this look quite arcane. I still wonder if hand-rolling a real scanner would beat the compactness of sscanf by making the code intentions a little more discernible, and have the benefits of avoiding my sscanf red-flag checker. But my wonder is not enough to stop me from accepting this hack as-is. Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --hfdhSgO8BvkFrfwx6lMOt9QbnQbOEprGQ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVJbO4AAoJEKeha0olJ0NqBx8IAKKZKJx2G/Bv1CNYxDpT1p+g 3E5u7D9UFf7bySS+tyaQ9mmPNSazqdwdQKfvz54N31c+DhxfoY/Gr243OJiw5XEM dGuBbbPI4bewcZnkKb0F+jhduj5nTdTe/kbqIRGku9KPajiEX4PNxvIYRdfhA+TP 2og+E8yMPsw2/RmYgSve1a5tSBGJiaGysXk1foYhJkeEKZI6ml267qbCh63+XAs3 wSkTE5ZkWI57WjNBlG7xWbwDi96ezH4hqN9bdiZMpe9/hfwss+jblNB6C7AdLbpq o2uNxcW/XJZMO2my0pgDWD8yRAGYrRsXdeHcle4Kef6u5i3b3GP6B7XI4KvXEBk= =E9nU -----END PGP SIGNATURE----- --hfdhSgO8BvkFrfwx6lMOt9QbnQbOEprGQ--