lkml.org 
[lkml]   [2019]   [Jul]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]


On Mon, 22 Jul 2019, Joe Perches wrote:

> Hello Julia.
>
> I just sent a patch to add yet another string copy mechanism.
>
> This could help avoid misuses of strscpy and strlcpy like this
> patch set:
>
> https://lore.kernel.org/lkml/cover.1562283944.git.joe@perches.com/T/
>
> A possible cocci script to do conversions could be:
>
> $ cat str.cpy.cocci
> @@
> expression e1;
> expression e2;
> @@
>
> - strscpy(e1, e2, sizeof(e1))
> + stracpy(e1, e2)
>
> @@
> expression e1;
> expression e2;
> @@
>
> - strlcpy(e1, e2, sizeof(e1))
> + stracpy(e1, e2)
>
> This obviously does not match the style of all the
> scripts/coccinelle cocci files, but this might be
> something that could be added improved and added.
>
> This script produces:
>
> $ spatch --in-place -sp-file str.cpy.cocci .
> $ git checkout tools/
> $ git diff --shortstat
> 958 files changed, 2179 insertions(+), 2655 deletions(-)
>
> The remainder of strlcpy and strscpy uses in the
> kernel would generally have a form like:
>
> strlcpy(to, from, DEFINE)
>
> where DEFINE is the specified size of to
>
> Could the cocci script above be updated to find
> and correct those styles as well?

I guess it would depend on what "to" is and what DEFINE expands into. For
example, in cpuidle-powernv.c, I see:

strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN);

and by poking around I see:

struct cpuidle_state {
char name[CPUIDLE_NAME_LEN];
char desc[CPUIDLE_DESC_LEN];
...
};

So I guess this case is ok.

I will look into it.

thanks,
julia

\
 
 \ /
  Last update: 2019-07-23 22:53    [W:0.144 / U:3.984 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site