From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXZ0d-0001iS-Og for qemu-devel@nongnu.org; Wed, 20 Jan 2010 06:46:03 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXZ0Z-0001h7-Qv for qemu-devel@nongnu.org; Wed, 20 Jan 2010 06:46:03 -0500 Received: from [199.232.76.173] (port=41838 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXZ0Z-0001h2-Lz for qemu-devel@nongnu.org; Wed, 20 Jan 2010 06:45:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48130) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXZ0Z-0005xf-1n for qemu-devel@nongnu.org; Wed, 20 Jan 2010 06:45:59 -0500 Message-ID: <4B56ECBC.40804@redhat.com> Date: Wed, 20 Jan 2010 12:45:00 +0100 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: [PATCH 07/17] block/vvfat.c: fix warnings with _FORTIFY_SOURCE References: <85e877202ec86dac15d392f5e88d5b5d76e3b02f.1263944807.git.quintela@redhat.com> <20100120103324.GA17856@redhat.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 Am 20.01.2010 12:09, schrieb Kirill A. Shutemov: > On Wed, Jan 20, 2010 at 12:33 PM, Daniel P. Berrange > wrote: >> 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 wrote: >>>> From: Kirill A. Shutemov >>>> >>>> CC block/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', declared with attribute warn_unused_result >>>> make: *** [block/vvfat.o] Error 1 >>>> CC block/vvfat.o >>>> In file included from /usr/include/stdio.h:912, >>>> from ./qemu-common.h:19, >>>> from block/vvfat.c:27: >>>> In function 'snprintf', >>>> inlined from 'init_directories' at block/vvfat.c:871, >>>> inlined from 'vvfat_open' at block/vvfat.c:1068: >>>> /usr/include/bits/stdio2.h:65: error: call to __builtin___snprintf_chk will always overflow destination buffer >>>> make: *** [block/vvfat.o] Error 1 >>>> >>>> Signed-off-by: Kirill A. Shutemov >>>> Signed-off-by: Juan Quintela >>>> --- >>>> block/vvfat.c | 9 +++++++-- >>>> 1 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, >>>> { >>>> direntry_t* entry=array_get_next(&(s->directory)); >>>> entry->attributes=0x28; /* archive | volume label */ >>>> - snprintf((char*)entry->name,11,"QEMU VVFAT"); >>>> + memcpy(entry->name,"QEMU VVF",8); >>>> + memcpy(entry->extension,"AT ",3); >>>> } >>> >>> Better to use >>> >>> memcpy(entry->name, "QEMU VVFAT", 11); >>> >>> memcpy() doesn't check bounds. >> >> It doesn't *currently* check bounds. > > No. memcpy() will never check bounds. It's totaly different from strcpy, > http://gcc.gnu.org/ml/gcc-patches/2009-06/msg00419.html Regardless if deliberately overflowing the buffer works or doesn't making it explicit is better. Someone might reorder the struct or add new fields in between (okay, unlikely in this case, but still) and you'll overflow into fields you never wanted to touch. Kevin