lkml.org 
[lkml]   [2009]   [Nov]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Documentation: Fix NUL termination of strncpy
Roel Kluin wrote:
> Ensure the copied strings are NUL terminated.
>
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
>> Rationale (please correct me if I'm wrong):
>
> diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
> index 6e25c26..4d71b0e 100644
> --- a/Documentation/accounting/getdelays.c
> +++ b/Documentation/accounting/getdelays.c
> @@ -303,7 +303,7 @@ int main(int argc, char *argv[])
> err(1, "Invalid rcv buf size\n");
> break;
> case 'm':
> - strncpy(cpumask, optarg, sizeof(cpumask));
> + strncpy(cpumask, optarg, sizeof(cpumask) - 1);

You need to explicitly NUL terminate strncpy():
http://www.pixelbeat.org/programming/gcc/string_buffers.html

cheers,
Pádraig.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2009-11-17 13:27    [W:0.080 / U:1.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site