From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41361) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blNge-0000N4-Lw for qemu-devel@nongnu.org; Sat, 17 Sep 2016 18:02:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1blNgd-0005lZ-K1 for qemu-devel@nongnu.org; Sat, 17 Sep 2016 18:02:16 -0400 References: <1471418906-27591-1-git-send-email-famz@redhat.com> <1471418906-27591-10-git-send-email-famz@redhat.com> From: Eric Blake Message-ID: <3f38c346-2fae-07f7-e204-d600a3310749@redhat.com> Date: Sat, 17 Sep 2016 17:02:07 -0500 MIME-Version: 1.0 In-Reply-To: <1471418906-27591-10-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="9AiWfOEQ4j6nRjesMjuVxdT5trGC4bpxc" Subject: Re: [Qemu-devel] [PATCH v6 9/9] tests: Add uuid tests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: kwolf@redhat.com, qemu-block@nongnu.org, sw@weilnetz.de, jcody@redhat.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com, pbonzini@redhat.com, mreitz@redhat.com, rth@twiddle.net This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --9AiWfOEQ4j6nRjesMjuVxdT5trGC4bpxc From: Eric Blake To: Fam Zheng , qemu-devel@nongnu.org Cc: kwolf@redhat.com, qemu-block@nongnu.org, sw@weilnetz.de, jcody@redhat.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com, pbonzini@redhat.com, mreitz@redhat.com, rth@twiddle.net Message-ID: <3f38c346-2fae-07f7-e204-d600a3310749@redhat.com> Subject: Re: [Qemu-devel] [PATCH v6 9/9] tests: Add uuid tests References: <1471418906-27591-1-git-send-email-famz@redhat.com> <1471418906-27591-10-git-send-email-famz@redhat.com> In-Reply-To: <1471418906-27591-10-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 08/17/2016 02:28 AM, Fam Zheng wrote: > Signed-off-by: Fam Zheng > --- > tests/Makefile.include | 2 + > tests/test-uuid.c | 173 +++++++++++++++++++++++++++++++++++++++++= ++++++++ > 2 files changed, 175 insertions(+) > create mode 100644 tests/test-uuid.c >=20 > + }, { /* Double '-' */ > + "0cc6c752--3961-4028-a286-c05cc616d396", > + }, { /* Too long */ > + "0000000000000000000000000000000000000000000000", > + }, { /* Invalid char in the beginning */ > + ")cc6c752--3961-4028-a286-c05cc616d396", Umm, why the double dash in this and the remaining tests? They are failing for the wrong reason. > + }, { /* Invalid char in the beginning, in extra */ > + ")0cc6c752--3961-4028-a286-c05cc616d396", > + }, { /* Invalid char in the middle */ > + "0cc6c752--39*1-4028-a286-c05cc616d396", > + }, { /* Invalid char in the middle, in extra */ > + "0cc6c752--39*61-4028-a286-c05cc616d396", > + }, { /* Invalid char in the end */ > + "0cc6c752--3961-4028-a286-c05cc616d39&", > + }, { /* Invalid char in the end, in extra */ > + "0cc6c752--3961-4028-a286-c05cc616d396&", And, I was able to quickly prove that you are missing a couple of tests: }, { /* Leading space and short end */ " 0cc6c752-3961-4028-a286-c05cc616d39", }, Whoops - that test fails. GTESTER tests/test-uuid ** ERROR:tests/test-uuid.c:126:test_uuid_parse: assertion failed (!r =3D=3D is_valid): (1 =3D=3D 0) Yay for sscanf() not doing what we want. :( We've had a latent bug for as long as we've been calling sscanf(UUID_FMT). Why does it fail, you ask? Because sscanf() skips leading spaces, and doesn't start counting the %02hhx parse until after the leading space; then the final %02hhx parse happily stops parsing with just 1 character. The string is the right length, but the wrong format. Also: }, { /* Short end and trailing space */ "0cc6c752-3961-4028-a286-c05cc616d39 ", You may want to add a followup patch that tightens parsing; perhaps using strspn() to double check that not only is the input string the right length, but also that it only has [a-fA-F0-9-], so that any whitespace that sneaks past sscanf() is detected. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --9AiWfOEQ4j6nRjesMjuVxdT5trGC4bpxc 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/ iQEcBAEBCAAGBQJX3b1fAAoJEKeha0olJ0NqgnEH/iHBGSJxyKyAvpNlT+fnx7J1 yPJZD5m0U/fQZvzCuX6ZDH9vykL8RLINKfmcHLL2qvZTzR7R/Mb7Z1leT0DiH6KE rVUHt51MmVppFMFTBNWlQRoBdMcDts+ckrpihk8io1OCFQH5aPpR7pSUmoXt0oE3 LrMIDLs25L7USx8jbe7pEj6gW+GLcWXqiOAopx7BA76Y3TqJYr7nqpDDFp4O7ZHI suEqDB3RntJH2va6I5E11qzU91k4mSjkuy5iyUgmZTzsIuCRpTSW34JGFPJdvIi/ ZVZoz5MwRrIUQ1nq65onWR601opo7HuPI9d1h4sAp7Ta9pY218Uc/XkX28Si3CU= =dYL0 -----END PGP SIGNATURE----- --9AiWfOEQ4j6nRjesMjuVxdT5trGC4bpxc--