Re: [PATCH] Documentation: Fix NUL termination of strncpy

From: Pádraig Brady
Date: Tue Nov 17 2009 - 07:25:35 EST


Roel Kluin wrote:
> Ensure the copied strings are NUL terminated.
>
> Signed-off-by: Roel Kluin <roel.kluin@xxxxxxxxx>
> ---
>> 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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/