From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:53747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QWOda-00060Z-O2 for qemu-devel@nongnu.org; Tue, 14 Jun 2011 04:06:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QWOdZ-0000GS-1k for qemu-devel@nongnu.org; Tue, 14 Jun 2011 04:06:14 -0400 Received: from mail-ww0-f53.google.com ([74.125.82.53]:48008) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QWOdY-0000GG-LN for qemu-devel@nongnu.org; Tue, 14 Jun 2011 04:06:12 -0400 Received: by wwj40 with SMTP id 40so5008027wwj.10 for ; Tue, 14 Jun 2011 01:06:11 -0700 (PDT) Date: Tue, 14 Jun 2011 09:06:02 +0100 From: Stefan Hajnoczi Message-ID: <20110614080602.GA19123@stefanha-thinkpad.localdomain> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , qemu-devel@nongnu.org, Christoph Hellwig On Sat, Jun 04, 2011 at 08:40:50AM +0800, Fam Zheng wrote: > vmdk_probe for mono flat images. > > Signed-off-by: Fam Zheng > --- > 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