qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Jim Meyering <jim@meyering.net>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 03/22] vmdk: relative_path: avoid buffer overrun
Date: Wed, 09 May 2012 14:12:33 +0200	[thread overview]
Message-ID: <4FAA5F31.4000308@redhat.com> (raw)
In-Reply-To: <87y5p1zhbv.fsf@rho.meyering.net>

Am 09.05.2012 14:09, schrieb Jim Meyering:
> Kevin Wolf wrote:
>> Am 09.05.2012 11:23, schrieb Jim Meyering:
>>> From: Jim Meyering <meyering@redhat.com>
>>>
>>> strncpy does not guarantee NUL-termination.
>>> Setting dest[n-1] = '\0' *before* calling strncpy(dest, src, n-1)
>>> is a no-op.  Use pstrcpy to ensure NUL-termination, not strncpy.
>>
>> It's not, it would only be a no-op before strncpy(dest, src, n). But
>> pstrcpy() is definitely nicer.
>>
>>> Signed-off-by: Jim Meyering <meyering@redhat.com>
>>> ---
>>>  block/vmdk.c | 3 +--
>>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/block/vmdk.c b/block/vmdk.c
>>> index 18e9b4c..045e279 100644
>>> --- a/block/vmdk.c
>>> +++ b/block/vmdk.c
>>> @@ -1319,8 +1319,7 @@ static int relative_path(char *dest, int dest_size,
>>>          return -1;
>>>      }
>>>      if (path_is_absolute(target)) {
>>> -        dest[dest_size - 1] = '\0';
>>> -        strncpy(dest, target, dest_size - 1);
>>> +        pstrcpy(dest, dest_size - 1, target);
>>
>> I think you mean pstrcpy(dest, dest_size, target).
> 
> Good points.  Thanks for the review.
> Here's the corrected commit:
> 
> From 78a367d846c95e84fddc971cbae544f24bc3455f Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering@redhat.com>
> Date: Mon, 7 May 2012 12:46:02 +0200
> Subject: [PATCH] vmdk: relative_path: use pstrcpy in place of strncpy
> 
> Avoid strncpy+manual-NUL-terminate.  Use pstrcpy instead.
> 
> Signed-off-by: Jim Meyering <meyering@redhat.com>
> ---
>  block/vmdk.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 18e9b4c..bfd7357 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -1319,8 +1319,7 @@ static int relative_path(char *dest, int dest_size,
>          return -1;
>      }
>      if (path_is_absolute(target)) {
> -        dest[dest_size - 1] = '\0';
> -        strncpy(dest, target, dest_size - 1);
> +        pstrcpy(dest, dest_size, target);
>          return 0;
>      }
>      while (base[i] == target[i]) {
> --
> 1.7.10.1.487.ga3935e6

Acked-by: Kevin Wolf <kwolf@redhat.com>

  reply	other threads:[~2012-05-09 12:12 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-09  9:23 [Qemu-devel] strncpy: best avoided (resend) Jim Meyering
2012-05-09  9:23 ` [Qemu-devel] [PATCH 01/22] block: avoid buffer overrun by using pstrcpy, not strncpy Jim Meyering
2012-05-09  9:50   ` Kevin Wolf
2012-05-09  9:23 ` [Qemu-devel] [PATCH 02/22] sheepdog: avoid a few buffer overruns Jim Meyering
2012-05-09  9:46   ` Kevin Wolf
2012-05-09 17:29     ` MORITA Kazutaka
2012-05-09  9:23 ` [Qemu-devel] [PATCH 03/22] vmdk: relative_path: avoid buffer overrun Jim Meyering
2012-05-09  9:54   ` Kevin Wolf
2012-05-09 12:09     ` Jim Meyering
2012-05-09 12:12       ` Kevin Wolf [this message]
2012-05-09  9:23 ` [Qemu-devel] [PATCH 04/22] hw/9pfs: " Jim Meyering
2012-05-09 13:08   ` Aneesh Kumar K.V
2012-05-09  9:23 ` [Qemu-devel] [PATCH 05/22] lm32: " Jim Meyering
2012-05-09  9:23 ` [Qemu-devel] [PATCH 06/22] os-posix: " Jim Meyering
2012-05-09  9:23 ` [Qemu-devel] [PATCH 07/22] ppc: avoid buffer overrun: use pstrcpy, not strncpy Jim Meyering
2012-05-09  9:23 ` [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup Jim Meyering
2012-05-09 13:29   ` Peter Maydell
2012-05-09 13:42     ` Jim Meyering
2012-05-09 13:51       ` Peter Maydell
2012-05-09 14:01         ` Jim Meyering
2012-05-09 14:07           ` Peter Maydell
2012-05-09 14:12             ` Jim Meyering
2012-05-09  9:23 ` [Qemu-devel] [PATCH 09/22] ui/vnc: simplify and avoid strncpy Jim Meyering
2012-05-09  9:23 ` [Qemu-devel] [PATCH 10/22] bt: replace fragile snprintf use and unwarranted strncpy Jim Meyering
2012-05-09  9:23 ` [Qemu-devel] [PATCH 11/22] virtio-9p: avoid unwarranted uses of strncpy Jim Meyering
2012-05-09 13:08   ` Aneesh Kumar K.V
2012-05-09  9:23 ` [Qemu-devel] [PATCH 12/22] virtio-9p: avoid unwarranted use " Jim Meyering
2012-05-09 13:07   ` Aneesh Kumar K.V
2012-05-09  9:23 ` [Qemu-devel] [PATCH 13/22] " Jim Meyering
2012-05-09 13:07   ` Aneesh Kumar K.V
2012-05-09 14:19     ` Jim Meyering
2012-05-09  9:23 ` [Qemu-devel] [PATCH 14/22] vscsi: avoid unwarranted strncpy Jim Meyering
2012-05-09 12:06   ` David Gibson
2012-05-09  9:23 ` [Qemu-devel] [PATCH 15/22] target-i386: use pstrcpy, not strncpy Jim Meyering
2012-05-09  9:24 ` [Qemu-devel] [PATCH 16/22] qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name Jim Meyering
2012-05-09 13:37   ` Luiz Capitulino
2012-05-09  9:24 ` [Qemu-devel] [PATCH 17/22] libcacard/vcard_emul_nss: use pstrcpy in place of strncpy Jim Meyering
2012-05-09  9:24 ` [Qemu-devel] [PATCH 18/22] acpi: remove strzcpy (strncpy-identical) function; just use strncpy Jim Meyering
2012-05-09 13:59   ` Peter Maydell
2012-05-09 14:15     ` Jim Meyering
2012-05-09 14:27       ` Paolo Bonzini
2012-05-09  9:24 ` [Qemu-devel] [PATCH 19/22] qcow2: mark this file's sole strncpy use as justified Jim Meyering
2012-05-09  9:55   ` Kevin Wolf
2012-05-09  9:24 ` [Qemu-devel] [PATCH 20/22] hw/r2d: add comment: this strncpy use is ok Jim Meyering
2012-05-09  9:24 ` [Qemu-devel] [PATCH 21/22] scsi: mark an strncpy use as valid Jim Meyering
2012-05-09  9:24 ` [Qemu-devel] [PATCH 22/22] doc: update HACKING wrt strncpy/pstrcpy Jim Meyering
2012-05-10 10:01 ` [Qemu-devel] strncpy: best avoided (resend) Kevin Wolf
2012-05-10 16:02   ` Jim Meyering
2012-05-10 17:29     ` Anthony Liguori
2012-05-10 17:33     ` Anthony Liguori

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=4FAA5F31.4000308@redhat.com \
    --to=kwolf@redhat.com \
    --cc=jim@meyering.net \
    --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).