From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXXsX-0002MX-BV for qemu-devel@nongnu.org; Wed, 20 Jan 2010 05:33:37 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXXsS-0002K8-0J for qemu-devel@nongnu.org; Wed, 20 Jan 2010 05:33:36 -0500 Received: from [199.232.76.173] (port=54324 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXXsR-0002K1-O2 for qemu-devel@nongnu.org; Wed, 20 Jan 2010 05:33:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54523) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXXsR-0005YH-6p for qemu-devel@nongnu.org; Wed, 20 Jan 2010 05:33:31 -0500 Date: Wed, 20 Jan 2010 10:33:24 +0000 From: "Daniel P. Berrange" Subject: Re: [Qemu-devel] Re: [PATCH 07/17] block/vvfat.c: fix warnings with _FORTIFY_SOURCE Message-ID: <20100120103324.GA17856@redhat.com> References: <85e877202ec86dac15d392f5e88d5b5d76e3b02f.1263944807.git.quintela@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Reply-To: "Daniel P. Berrange" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Kirill A. Shutemov" Cc: qemu-devel@nongnu.org, Juan Quintela On Wed, Jan 20, 2010 at 08:19:26AM +0200, Kirill A. Shutemov wrote: > On Wed, Jan 20, 2010 at 1:56 AM, Juan Quintela wr= ote: > > From: Kirill A. Shutemov > > > > CC =A0 =A0block/vvfat.o > > cc1: warnings being treated as errors > > block/vvfat.c: In function 'commit_one_file': > > block/vvfat.c:2259: error: ignoring return value of 'ftruncate', decl= ared with attribute warn_unused_result > > make: *** [block/vvfat.o] Error 1 > > =A0CC =A0 =A0block/vvfat.o > > In file included from /usr/include/stdio.h:912, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 from ./qemu-common.h:19, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 from block/vvfat.c:27: > > In function 'snprintf', > > =A0 =A0inlined from 'init_directories' at block/vvfat.c:871, > > =A0 =A0inlined from 'vvfat_open' at block/vvfat.c:1068: > > /usr/include/bits/stdio2.h:65: error: call to __builtin___snprintf_ch= k will always overflow destination buffer > > make: *** [block/vvfat.o] Error 1 > > > > Signed-off-by: Kirill A. Shutemov > > Signed-off-by: Juan Quintela > > --- > > =A0block/vvfat.c | =A0 =A09 +++++++-- > > =A01 files changed, 7 insertions(+), 2 deletions(-) > > > > diff --git a/block/vvfat.c b/block/vvfat.c > > index 063f731..df957e5 100644 > > --- a/block/vvfat.c > > +++ b/block/vvfat.c > > @@ -868,7 +868,8 @@ static int init_directories(BDRVVVFATState* s, > > =A0 =A0 { > > =A0 =A0 =A0 =A0direntry_t* entry=3Darray_get_next(&(s->directory)); > > =A0 =A0 =A0 =A0entry->attributes=3D0x28; /* archive | volume label */ > > - =A0 =A0 =A0 snprintf((char*)entry->name,11,"QEMU VVFAT"); > > + =A0 =A0 =A0 memcpy(entry->name,"QEMU VVF",8); > > + =A0 =A0 =A0 memcpy(entry->extension,"AT ",3); > > =A0 =A0 } >=20 > Better to use >=20 > memcpy(entry->name, "QEMU VVFAT", 11); >=20 > memcpy() doesn't check bounds. It doesn't *currently* check bounds. If we want to explicitly fill 2 fields at once, then we should redeclare this to have a=20 union with one part comprising the entire buffer, thus avoiding the need for delibrate buffer overruns. Regards, Daniel --=20 |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange= / :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.or= g :| |: http://autobuild.org -o- http://search.cpan.org/~danberr= / :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 950= 5 :|