lkml.org 
[lkml]   [2012]   [Aug]   [29]   [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 Wed, Aug 29, 2012 at 08:28:47AM +0200, Jim Meyering wrote:
> Dan Carpenter wrote:
> > On Fri, Aug 24, 2012 at 01:23:29PM +0200, Jim Meyering wrote:
> >> In that case, what would you think of a patch to use strcpy instead?
> >>
> >> - strncpy(object->comm, current->comm, sizeof(object->comm));
> >> + strcpy(object->comm, current->comm);
> >
> > Another option would be to use strlcpy(). It's slightly neater than
> > the strncpy() followed by a NUL assignment.
> >
> >> Is there a preferred method of adding a static_assert-like statement?
> >> I see compile_time_assert and a few similar macros, but I haven't
> >> spotted anything that is used project-wide.
> >
> > BUILD_BUG_ON().
>
> Hi Dan,
>
> Thanks for the feedback and tip. How about this patch?
>

I'm not someone who can approve kmemleak patches, but that's
horrible. I'm not sure we need a BUILD_BUG_ON(), I was just telling
you the standard way to do a build time assert. If we did put the
assert in then it should only be in one place in the header file
where the data is decared instead of repeated over and over.

I like strlcpy(). Both strcpy() and strlcpy() will silence your
static checker tool. strcpy() may be better, but strlcpy() feels
very safe so that might be preferred.

regards,
dan carpenter



\
 
 \ /
  Last update: 2012-08-29 18:41    [W:0.053 / U:0.096 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site