From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ku2dX-0006cb-IL for qemu-devel@nongnu.org; Sun, 26 Oct 2008 06:14:19 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ku2dV-0006cG-OV for qemu-devel@nongnu.org; Sun, 26 Oct 2008 06:14:18 -0400 Received: from [199.232.76.173] (port=37925 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ku2dV-0006cD-Gs for qemu-devel@nongnu.org; Sun, 26 Oct 2008 06:14:17 -0400 Received: from wf-out-1314.google.com ([209.85.200.174]:53206) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ku2dV-00086G-79 for qemu-devel@nongnu.org; Sun, 26 Oct 2008 06:14:17 -0400 Received: by wf-out-1314.google.com with SMTP id 27so1570903wfd.4 for ; Sun, 26 Oct 2008 03:14:15 -0700 (PDT) Message-ID: Date: Sun, 26 Oct 2008 12:14:15 +0200 From: "Blue Swirl" Subject: Re: [Qemu-devel] [5531] Replace uses of strncpy (a GNU extension) with Qemu pstrcpy In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org On 10/25/08, malc wrote: > On Sat, 25 Oct 2008, Blue Swirl wrote: > > > > Revision: 5531 > > > http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5531 > > Author: blueswir1 > > Date: 2008-10-25 11:21:28 +0000 (Sat, 25 Oct 2008) > > > > > > [..snip..] > > > > Modified: trunk/block-vvfat.c > > > =================================================================== > > --- trunk/block-vvfat.c 2008-10-25 11:19:14 UTC (rev 5530) > > +++ trunk/block-vvfat.c 2008-10-25 11:21:28 UTC (rev 5531) > > @@ -625,7 +625,7 @@ > > > > entry=array_get_next(&(s->directory)); > > memset(entry->name,0x20,11); > > - strncpy((char*)entry->name,filename,i); > > + pstrcpy((char*)entry->name, i, filename); > > > > if(j > 0) > > for (i = 0; i < 3 && filename[j+1+i]; i++) > > > > This is wrong and broke vvfat: > > a. pstrcpy is abused, second argument should be the size of the output > buffer, not the length of the second argument It's actually not the raw length, but MAX(length, 8). > b. even if replaced with pstrcpy(.., meta_sizeof(entry->name), ...) > it would have been still wrong, since we must _i_ elements of > entry->name and NOT try to zero terminate the output buffer > > I think this was one of those rare cases when strncpy was used in > accordance with it's definition and not what programmer was imagining. > > I think plain memcpy(...,filename,i) is the most warranted thing here. Yes, that should do the right thing. I think the cutils.c needs some more commenting to document these corner cases.