Re: rfc: treewide scripted patch mechanism? (was: Re: [PATCH] Makefile: Convert -Wimplicit-fallthrough=3 to just -Wimplicit-fallthrough for clang)QUILT

From: Geert Uytterhoeven
Date: Mon Aug 26 2019 - 04:58:54 EST

Hi Linus,

On Wed, Aug 21, 2019 at 2:41 AM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Tue, Aug 20, 2019 at 4:37 PM Joe Perches <joe@xxxxxxxxxxx> wrote:
> > > So I'm putting my foot down on yet another broken string copy
> > > interface from people who do not understand this fundamental issue.
> >
> > I think you are mistaken about the stracpy limits as
> > the only limit is not the source size but the dest.
> >
> > Why should the source be size limited?
> You just proved my point. You don't understand that sources can also
> be limited, and the limit on a source can be *smaller* than the limit
> of a destination.
> Did we learn *NOTHING* from the complete and utter disaster that was strlcpy()?
> Do you not understand why strlcpy() was unacceptably bad, and why the
> people who converted strncpy() to it introduced real bugs?
> The fact is, it's not just the destination that has a size limit. The
> source often has one too.
> And no, the source is not always guaranteed to be NUL-terminated, nor
> is the source buffer guaranteed to be larger than the destination
> buffer.
> Now, if you *know* that the source is smaller than the destination
> size, you can do:
> len = strnlen(src, srclen);
> memcpy(dst, len);
> dst[len] = 0;
> and that's not wrong, but that works only when
> (a) you actually do the above
> (b) you have no data races on src (or you at least only require that
> 'dst' is NUL-terminated, not that 'len' is necessarily the correct
> length of the result
> (c) you actually know as the programmer that yes, the source is
> definitely smaller than the destination.
> and honestly, people don't get _any_ of that right.

(d) you know the untouched trailing end of dst[] does not leak data.

Anything else we're missing?



Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds