qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Blue Swirl" <blauwirbel@gmail.com>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [5531] Replace uses of strncpy (a GNU extension) with Qemu pstrcpy
Date: Sun, 26 Oct 2008 12:14:15 +0200	[thread overview]
Message-ID: <f43fc5580810260314h71b3f195i2c37517c01d0d35a@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0810252239020.4151@linmac.oyster.ru>

On 10/25/08, malc <av1474@comtv.ru> 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.

      reply	other threads:[~2008-10-26 10:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-25 11:21 [Qemu-devel] [5531] Replace uses of strncpy (a GNU extension) with Qemu pstrcpy Blue Swirl
2008-10-25 11:29 ` Blue Swirl
2008-10-25 11:55   ` andrzej zaborowski
2008-10-25 18:47 ` malc
2008-10-26 10:14   ` Blue Swirl [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f43fc5580810260314h71b3f195i2c37517c01d0d35a@mail.gmail.com \
    --to=blauwirbel@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).