From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:58590) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QWhgR-0000An-2a for qemu-devel@nongnu.org; Wed, 15 Jun 2011 00:26:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QWhgP-0005BP-Jw for qemu-devel@nongnu.org; Wed, 15 Jun 2011 00:26:26 -0400 Received: from mail-vx0-f173.google.com ([209.85.220.173]:56321) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QWhgP-0005BJ-A7 for qemu-devel@nongnu.org; Wed, 15 Jun 2011 00:26:25 -0400 Received: by vxb37 with SMTP id 37so30290vxb.4 for ; Tue, 14 Jun 2011 21:26:24 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20110614080602.GA19123@stefanha-thinkpad.localdomain> References: <20110614080602.GA19123@stefanha-thinkpad.localdomain> From: Fam Zheng Date: Wed, 15 Jun 2011 12:26:04 +0800 Message-ID: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: Stefan Hajnoczi Cc: Kevin Wolf , qemu-devel@nongnu.org, Christoph Hellwig On Tue, Jun 14, 2011 at 4:06 PM, Stefan Hajnoczi wrote= : > On Sat, Jun 04, 2011 at 08:40:50AM +0800, Fam Zheng wrote: >> vmdk_probe for mono flat images. >> >> Signed-off-by: Fam Zheng >> --- >> =C2=A0block/vmdk.c | =C2=A0 13 ++++++++++--- >> =C2=A01 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) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 0; >> =C2=A0 =C2=A0 =C2=A0magic =3D be32_to_cpu(*(uint32_t *)buf); >> =C2=A0 =C2=A0 =C2=A0if (magic =3D=3D VMDK3_MAGIC || >> - =C2=A0 =C2=A0 =C2=A0 =C2=A0magic =3D=3D VMDK4_MAGIC) >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0magic =3D=3D VMDK4_MAGIC) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 100; >> - =C2=A0 =C2=A0else >> - =C2=A0 =C2=A0 =C2=A0 =C2=A0return 0; >> + =C2=A0 =C2=A0} else { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0char *cid_p, *ct_p, *extent_p; >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0cid_p =3D strstr((char *)buf, "CID"); >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0ct_p =3D strstr((char *)buf, "createType"); >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0extent_p =3D strstr((char *)buf, "RW"); >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (cid_p && ct_p && extent_p) >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 100; > > NUL-terminated string functions cannot be used for probing because the > input file may be invalid. =C2=A0If 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". =C2=A0"cid", "CiD", and "CID" should all be allowed. > > Do non-monolithic vmdk images always have "# Disk DescriptorFile" as the > first line? =C2=A0Perhaps you can test for that using memcmp(3) instead. No guarantee in specification, although VMware does start descriptors with such a line "# Disk DescriptorFile". But is it proper that we make this assumption? --=20 Best regards! Fam Zheng