Re: [PATCH v3] lib/string.c: implement stpcpy

2020-09-06 Thread Kees Cook
On Thu, Aug 27, 2020 at 12:58:35AM +0900, Masahiro Yamada wrote: > On Tue, Aug 25, 2020 at 10:58 PM Nick Desaulniers > wrote: > > [...] > > +/** > > + * stpcpy - copy a string from src to dest returning a pointer to the new > > end > > + * of dest, including src's %NUL-terminator. May

RE: [PATCH v3] lib/string.c: implement stpcpy

2020-09-01 Thread David Laight
> Of course, no "True Scotsman" would accidentally misuse C string.h API! > https://yourlogicalfallacyis.com/no-true-scotsman Google will find plenty of: str[strlen(str)] = 0; David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No:

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-31 Thread Nick Desaulniers
On Thu, Aug 27, 2020 at 1:59 AM Andy Shevchenko wrote: > > strcpy() is not a bad API for the cases when you know what you are > doing. A problem that most of the developers do not know what they are > doing. > No need to split everything to bad and good by its name or semantics, > each API has

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-28 Thread Andy Shevchenko
On Fri, Aug 28, 2020 at 1:26 AM Kees Cook wrote: > > On Thu, Aug 27, 2020 at 11:05:42PM +0300, Andy Shevchenko wrote: > > In general it's better to have a robust API, but what may go wrong > > with the interface where we have no length of the buffer passed, but > > we all know that it's

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-27 Thread Kees Cook
On Thu, Aug 27, 2020 at 11:05:42PM +0300, Andy Shevchenko wrote: > In general it's better to have a robust API, but what may go wrong > with the interface where we have no length of the buffer passed, but > we all know that it's PAGE_SIZE? > So, what's wrong with doing something like >

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-27 Thread Andy Shevchenko
On Thu, Aug 27, 2020 at 9:30 PM Kees Cook wrote: > > On Thu, Aug 27, 2020 at 11:59:24AM +0300, Andy Shevchenko wrote: > > strcpy() is not a bad API for the cases when you know what you are > > doing. A problem that most of the developers do not know what they are > > doing. > > No need to split

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-27 Thread Kees Cook
On Thu, Aug 27, 2020 at 12:37:03PM -0700, Joe Perches wrote: > On Thu, 2020-08-27 at 11:30 -0700, Kees Cook wrote: > > > Most of the uses of strcpy() in the kernel are just copying between two > > known-at-compile-time NUL-terminated character arrays. We had wanted to > > introduce stracpy() for

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-27 Thread Joe Perches
On Thu, 2020-08-27 at 11:30 -0700, Kees Cook wrote: > Most of the uses of strcpy() in the kernel are just copying between two > known-at-compile-time NUL-terminated character arrays. We had wanted to > introduce stracpy() for this, but Linus objected to yet more string > functions.

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-27 Thread Kees Cook
On Thu, Aug 27, 2020 at 11:59:24AM +0300, Andy Shevchenko wrote: > strcpy() is not a bad API for the cases when you know what you are > doing. A problem that most of the developers do not know what they are > doing. > No need to split everything to bad and good by its name or semantics, > each API

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-27 Thread Kees Cook
On Wed, Aug 26, 2020 at 07:42:17PM -0700, Joe Perches wrote: > On Wed, 2020-08-26 at 19:33 -0700, Kees Cook wrote: > > On Wed, Aug 26, 2020 at 04:57:41PM -0700, Joe Perches wrote: > > > On Wed, 2020-08-26 at 16:38 -0700, Kees Cook wrote: > > > > On Thu, Aug 27, 2020 at 07:59:45AM +0900, Masahiro

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-27 Thread Andy Shevchenko
On Thu, Aug 27, 2020 at 2:40 AM Kees Cook wrote: > On Thu, Aug 27, 2020 at 07:59:45AM +0900, Masahiro Yamada wrote: > > On Thu, Aug 27, 2020 at 1:58 AM Nick Desaulniers > > wrote: > > > On Wed, Aug 26, 2020 at 9:57 AM Joe Perches wrote: > > > > On Thu, 2020-08-27 at 01:49 +0900, Masahiro Yamada

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Joe Perches
On Wed, 2020-08-26 at 19:33 -0700, Kees Cook wrote: > On Wed, Aug 26, 2020 at 04:57:41PM -0700, Joe Perches wrote: > > On Wed, 2020-08-26 at 16:38 -0700, Kees Cook wrote: > > > On Thu, Aug 27, 2020 at 07:59:45AM +0900, Masahiro Yamada wrote: > > [] > > > > OK, then stpcpy(), strcpy() and sprintf()

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Kees Cook
On Wed, Aug 26, 2020 at 04:57:41PM -0700, Joe Perches wrote: > On Wed, 2020-08-26 at 16:38 -0700, Kees Cook wrote: > > On Thu, Aug 27, 2020 at 07:59:45AM +0900, Masahiro Yamada wrote: > [] > > > OK, then stpcpy(), strcpy() and sprintf() > > > have the same level of unsafety. > > > > Yes. And even

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Joe Perches
On Wed, 2020-08-26 at 16:38 -0700, Kees Cook wrote: > On Thu, Aug 27, 2020 at 07:59:45AM +0900, Masahiro Yamada wrote: [] > > OK, then stpcpy(), strcpy() and sprintf() > > have the same level of unsafety. > > Yes. And even snprintf() is dangerous because its return value is how > much it WOULD

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Kees Cook
On Thu, Aug 27, 2020 at 07:59:45AM +0900, Masahiro Yamada wrote: > On Thu, Aug 27, 2020 at 1:58 AM Nick Desaulniers > wrote: > > > > On Wed, Aug 26, 2020 at 9:57 AM Joe Perches wrote: > > > > > > On Thu, 2020-08-27 at 01:49 +0900, Masahiro Yamada wrote: > > > > I do not have time to keep track

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Masahiro Yamada
On Thu, Aug 27, 2020 at 1:58 AM Nick Desaulniers wrote: > > On Wed, Aug 26, 2020 at 9:57 AM Joe Perches wrote: > > > > On Thu, 2020-08-27 at 01:49 +0900, Masahiro Yamada wrote: > > > I do not have time to keep track of the discussion fully, > > > but could you give me a little more context why >

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Nick Desaulniers
On Wed, Aug 26, 2020 at 9:57 AM Joe Perches wrote: > > On Thu, 2020-08-27 at 01:49 +0900, Masahiro Yamada wrote: > > I do not have time to keep track of the discussion fully, > > but could you give me a little more context why > > the usage of stpcpy() is not recommended ? > > > > The

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Joe Perches
On Thu, 2020-08-27 at 01:49 +0900, Masahiro Yamada wrote: > I do not have time to keep track of the discussion fully, > but could you give me a little more context why > the usage of stpcpy() is not recommended ? > > The implementation of strcpy() is almost the same. > It is unclear to me what

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Masahiro Yamada
On Tue, Aug 25, 2020 at 10:58 PM Nick Desaulniers wrote: > > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in parsing format strings.

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Masahiro Yamada
On Tue, Aug 25, 2020 at 10:58 PM Nick Desaulniers wrote: > > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in parsing format strings.

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Sedat Dilek
On Tue, Aug 25, 2020 at 3:58 PM 'Nick Desaulniers' via Clang Built Linux wrote: > > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-26 Thread Kees Cook
On Tue, Aug 25, 2020 at 07:00:00AM -0700, Nick Desaulniers wrote: > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in parsing format

Re: [PATCH v3] lib/string.c: implement stpcpy

2020-08-25 Thread Nathan Chancellor
On Tue, Aug 25, 2020 at 06:58:36AM -0700, Nick Desaulniers wrote: > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in parsing format

[PATCH v3] lib/string.c: implement stpcpy

2020-08-25 Thread Nick Desaulniers
LLVM implemented a recent "libcall optimization" that lowers calls to `sprintf(dest, "%s", str)` where the return value is used to `stpcpy(dest, str) - dest`. This generally avoids the machinery involved in parsing format strings. `stpcpy` is just like `strcpy` except it returns the pointer to

[PATCH v3] lib/string.c: implement stpcpy

2020-08-25 Thread Nick Desaulniers
LLVM implemented a recent "libcall optimization" that lowers calls to `sprintf(dest, "%s", str)` where the return value is used to `stpcpy(dest, str) - dest`. This generally avoids the machinery involved in parsing format strings. `stpcpy` is just like `strcpy` except it returns the pointer to