qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Fam Zheng <famz@redhat.com>, 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
Subject: Re: [Qemu-devel] [PATCH v6 9/9] tests: Add uuid tests
Date: Sat, 17 Sep 2016 17:02:07 -0500	[thread overview]
Message-ID: <3f38c346-2fae-07f7-e204-d600a3310749@redhat.com> (raw)
In-Reply-To: <1471418906-27591-10-git-send-email-famz@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2409 bytes --]

On 08/17/2016 02:28 AM, Fam Zheng wrote:
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  tests/Makefile.include |   2 +
>  tests/test-uuid.c      | 173 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 175 insertions(+)
>  create mode 100644 tests/test-uuid.c
> 

> +    }, { /* 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 ==
is_valid): (1 == 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.


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2016-09-17 22:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17  7:28 [Qemu-devel] [PATCH v6 0/9] UUID clean ups for 2.8 Fam Zheng
2016-08-17  7:28 ` [Qemu-devel] [PATCH v6 1/9] util: Add UUID API Fam Zheng
2016-09-17 21:29   ` Eric Blake
2016-09-18  1:46     ` Fam Zheng
2016-08-17  7:28 ` [Qemu-devel] [PATCH v6 2/9] vhdx: Use QEMU " Fam Zheng
2016-09-17 21:31   ` Eric Blake
2016-08-17  7:28 ` [Qemu-devel] [PATCH v6 3/9] vdi: " Fam Zheng
2016-09-17 21:32   ` Eric Blake
2016-09-18  5:48   ` Stefan Weil
2016-08-17  7:28 ` [Qemu-devel] [PATCH v6 4/9] vpc: " Fam Zheng
2016-09-17 21:33   ` Eric Blake
2016-08-17  7:28 ` [Qemu-devel] [PATCH v6 5/9] crypto: Switch to " Fam Zheng
2016-09-17 21:34   ` Eric Blake
2016-08-17  7:28 ` [Qemu-devel] [PATCH v6 6/9] tests: No longer dependent on CONFIG_UUID Fam Zheng
2016-09-17 21:34   ` Eric Blake
2016-08-17  7:28 ` [Qemu-devel] [PATCH v6 7/9] configure: Remove detection code for UUID Fam Zheng
2016-09-17 21:35   ` Eric Blake
2016-08-17  7:28 ` [Qemu-devel] [PATCH v6 8/9] vl: Switch qemu_uuid to QemuUUID Fam Zheng
2016-09-17 21:38   ` Eric Blake
2016-09-17 21:50     ` Eric Blake
2016-08-17  7:28 ` [Qemu-devel] [PATCH v6 9/9] tests: Add uuid tests Fam Zheng
2016-09-17 22:02   ` Eric Blake [this message]
2016-09-03  5:07 ` [Qemu-devel] [PATCH v6 0/9] UUID clean ups for 2.8 Fam Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f38c346-2fae-07f7-e204-d600a3310749@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).