RE: [PATCH v2] powerpc/64: Fix build failure with GCC 8.1
From: David Laight
Date: Tue May 29 2018 - 11:23:32 EST
From: Christophe LEROY
> Sent: 29 May 2018 10:37
...
> >>>> - strncpy(new_part->header.name, name, 12);
> >>>> + memcpy(new_part->header.name, name, strnlen(name,
> >>>> sizeof(new_part->header.name)));
> >>>
> >>>
> >>> The comment for nvram_header.lgnth says:
> >>>
> >>> /* Terminating null required only for names < 12 chars. */
> >>>
> >>> This will not terminate the string with a zero (the struct is
> >>> allocated with kmalloc).
> >>> So the original code is correct, the new one isn't.
> >>
> >> Right, then I have to first zeroize the destination.
> >
> > Using kzalloc() instead of kmalloc() will do.
> >
> > Still, papering around these warnings seems to obscure things, IMHO.
> > And it increases code size, as you had to add a call to strnlen().
>
> Right but then, what is the best solution to elimate that warning ?
Time to add the I_really_mean_strncy() function.
David