[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 03/22] vmdk: relative_path: avoid buffer overrun
From: |
Kevin Wolf |
Subject: |
Re: [Qemu-devel] [PATCH 03/22] vmdk: relative_path: avoid buffer overrun |
Date: |
Wed, 09 May 2012 14:12:33 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 |
Am 09.05.2012 14:09, schrieb Jim Meyering:
> Kevin Wolf wrote:
>> Am 09.05.2012 11:23, schrieb Jim Meyering:
>>> From: Jim Meyering <address@hidden>
>>>
>>> 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 <address@hidden>
>>> ---
>>> 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 <address@hidden>
> 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 <address@hidden>
> ---
> 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 <address@hidden>
- [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, (continued)
- [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Peter Maydell, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Peter Maydell, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Peter Maydell, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/09
[Qemu-devel] [PATCH 03/22] vmdk: relative_path: avoid buffer overrun, Jim Meyering, 2012/05/09
[Qemu-devel] [PATCH 13/22] virtio-9p: avoid unwarranted use of strncpy, Jim Meyering, 2012/05/09
[Qemu-devel] [PATCH 05/22] lm32: avoid buffer overrun, Jim Meyering, 2012/05/09
[Qemu-devel] [PATCH 19/22] qcow2: mark this file's sole strncpy use as justified, Jim Meyering, 2012/05/09
[Qemu-devel] [PATCH 21/22] scsi: mark an strncpy use as valid, Jim Meyering, 2012/05/09
Re: [Qemu-devel] strncpy: best avoided (resend), Kevin Wolf, 2012/05/10