lkml.org 
[lkml]   [2012]   [Aug]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] kmemleak: avoid buffer overrun: NUL-terminate strncpy-copied command
On Mon, Aug 20, 2012 at 05:55:22PM +0100, Jim Meyering wrote:
> From: Jim Meyering <meyering@redhat.com>
>
> strncpy NUL-terminates only when the length of the source string
> is smaller than the size of the destination buffer.
> The two other strncpy uses (just preceding) happen to be ok
> with the current TASK_COMM_LEN (16), because the literals
> "hardirq" and "softirq" are both shorter than 16. However,
> technically it'd be better to use strcpy along with a
> compile-time assertion that they fit in the buffer.
>
> Signed-off-by: Jim Meyering <meyering@redhat.com>
> ---
> mm/kmemleak.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index 45eb621..947257f 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -555,6 +555,7 @@ static struct kmemleak_object *create_object(unsigned long ptr, size_t size,
> * case, the command line is not correct.
> */
> strncpy(object->comm, current->comm, sizeof(object->comm));
> + object->comm[sizeof(object->comm) - 1] = 0;

Does it really matter here? object->comm[] and current->comm[] have the
same size, TASK_COMM_LEN.

--
Catalin


\
 
 \ /
  Last update: 2012-08-24 13:01    [W:0.480 / U:0.256 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site