From: malc <av1474@comtv.ru>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [5531] Replace uses of strncpy (a GNU extension) with Qemu pstrcpy
Date: Sat, 25 Oct 2008 22:47:25 +0400 (MSD) [thread overview]
Message-ID: <Pine.LNX.4.64.0810252239020.4151@linmac.oyster.ru> (raw)
In-Reply-To: <E1KthCz-0006P6-Bz@cvs.savannah.gnu.org>
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
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.
[..snip..]
--
mailto:av1474@comtv.ru
next prev parent reply other threads:[~2008-10-25 18:47 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 [this message]
2008-10-26 10:14 ` Blue Swirl
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=Pine.LNX.4.64.0810252239020.4151@linmac.oyster.ru \
--to=av1474@comtv.ru \
--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).