qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image
Date: Tue, 14 Jun 2011 09:06:02 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Sat, Jun 04, 2011 at 08:40:50AM +0800, Fam Zheng wrote:
> vmdk_probe for mono flat images.
> 
> Signed-off-by: Fam Zheng <address@hidden>
> ---
>  block/vmdk.c |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index f787528..bf8d02a 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -101,10 +101,17 @@ static int vmdk_probe(const uint8_t *buf, int
> buf_size, const char *filename)
>          return 0;
>      magic = be32_to_cpu(*(uint32_t *)buf);
>      if (magic == VMDK3_MAGIC ||
> -        magic == VMDK4_MAGIC)
> +        magic == VMDK4_MAGIC) {
>          return 100;
> -    else
> -        return 0;
> +    } else {
> +        char *cid_p, *ct_p, *extent_p;
> +        cid_p = strstr((char *)buf, "CID");
> +        ct_p = strstr((char *)buf, "createType");
> +        extent_p = strstr((char *)buf, "RW");
> +        if (cid_p && ct_p && extent_p)
> +            return 100;

NUL-terminated string functions cannot be used for probing because the
input file may be invalid.  If the magic number matches but there is no
NUL in the buffer then the strstr(3) will run off the end of the buffer.

Also note that the specification says "The descriptor file is not
case-sensitive".  "cid", "CiD", and "CID" should all be allowed.

Do non-monolithic vmdk images always have "# Disk DescriptorFile" as the
first line?  Perhaps you can test for that using memcmp(3) instead.

Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]