Re: [PATCH 14/18] kdb_support: change strncpy+truncation to strlcpy

From: Dominique Martinet
Date: Fri Jul 13 2018 - 11:19:10 EST


Daniel Thompson wrote on Fri, Jul 13, 2018:
> On Fri, Jul 13, 2018 at 03:25:58AM +0200, Dominique Martinet wrote:
> > Generated by scripts/coccinelle/misc/strncpy_truncation.cocci
> >
> > Signed-off-by: Dominique Martinet <asmadeus@xxxxxxxxxxxxx>
>
> It would have been good for you to mention in the changelog how
> you reviewed your change to verify that the extra zero padding
> from strncpy() isn't required.

I'm sorry, I went a bit too fast with the send-email button on this
path series; I agree it is lacking.

> However... I have taken a look and can't see any problem so:
>
> Reviewed-by: Daniel Thompson <daniel.thompson@xxxxxxxxxx>

Thank you for the review, I will update the commit message with more
details and change strlcpy to strscpy in a v2


David Laight wrote on Fri, Jul 13, 2018:
> > - strncpy(knt1, symtab->sym_name, knt1_size);
> > - knt1[knt1_size-1] = '\0';
> > + strlcpy(knt1, symtab->sym_name, knt1_size);
>
> You'd be better using strscpy() not strlcpy().
> The return value of strlcpy() is the length of the source string.
> If the source string isn't '\0' terminated horrid things happen.

I was suggested to use strlcpy for drm and didn't realize this at this
point, but you are correct; strlcpy is far from being as protective.

I'll update the coccinelle patch to use strscpy and resend this.


> David
>
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes,
> MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
> P Please consider the environment and don't print this e-mail unless
> you really need to

(By the way, your e-mail client sends both html and text, but the text
version only included the footer so my mail client, which prefers text,
was displaying an empty mail message. If possible I would appreciate if
you could disable either version so as to get a coherent message)

--
Dominique Martinet