Re: [PATCH v4] checkpatch: add check for snprintf to scnprintf

2024-04-10 Thread Lee Jones
On Mon, 08 Apr 2024, Justin Stitt wrote: > I am going to quote Lee Jones who has been doing some snprintf -> > scnprintf refactorings: > > "There is a general misunderstanding amongst engineers that > {v}snprintf() returns the length of the data *actually* encoded into the > destination array. H

Re: [PATCH] xfs: replace deprecated strncpy with strscpy_pad

2024-04-10 Thread Justin Stitt
L_MAX); > > + strscpy_pad(label, sbp->sb_fname); > > Is sbp->sb_fname itself NUL-terminated? This looks like another case of > needing the memtostr() helper? > I sent a patch [1]. Obviously it depends on your implementation patch landing first; what tree should it go to

[PATCH v2] xfs: replace deprecated strncpy with memtostr_pad

2024-04-10 Thread Justin Stitt
strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. sbp->sb_fname may not be NUL-terminated while label is expected to be. memtostr best describes this behavior, specifically, use the pad variant s

[PATCH v2] xfs: xattr: replace strncpy and check for truncation

2024-04-10 Thread Justin Stitt
strncpy is deprecated and as such we should prefer less ambiguous and more robust string interfaces [1]. There's a lot of manual memory management to get a prefix and name into a string. Let's use an easier to understand and more robust interface in scnprintf() to accomplish the same task while en

Re: [PATCH 1/5] string.h: Introduce memtostr() and memtostr_pad()

2024-04-10 Thread Kees Cook
On Wed, Apr 10, 2024 at 07:08:10AM +0300, Andy Shevchenko wrote: > On Wed, Apr 10, 2024 at 5:31 AM Kees Cook wrote: > > > > Another ambiguous use of strncpy() is to copy from strings that may not > > be NUL-terminated. These cases depend on having the destination buffer > > be explicitly larger th

Re: [PATCH] trace: events: cleanup deprecated strncpy uses

2024-04-10 Thread Steven Rostedt
On Wed, 10 Apr 2024 11:41:18 -0400 Chuck Lever wrote: > > If anything, it needs to be: > > > > __string_len(acceptor, data, len) > > > > as the macro code has changed recently, and the current code will crash! > > A general question: > > Is there a test suite we should run regul

Re: [PATCH] trace: events: cleanup deprecated strncpy uses

2024-04-10 Thread Chuck Lever
On Wed, Apr 10, 2024 at 11:36:14AM -0400, Steven Rostedt wrote: > On Mon, 01 Apr 2024 23:48:52 + > Justin Stitt wrote: > > > diff --git a/include/trace/events/rpcgss.h b/include/trace/events/rpcgss.h > > index ba2d96a1bc2f..274c297f1b15 100644 > > --- a/include/trace/events/rpcgss.h > > +++ b

Re: [PATCH] trace: events: cleanup deprecated strncpy uses

2024-04-10 Thread Steven Rostedt
On Mon, 01 Apr 2024 23:48:52 + Justin Stitt wrote: > diff --git a/include/trace/events/rpcgss.h b/include/trace/events/rpcgss.h > index ba2d96a1bc2f..274c297f1b15 100644 > --- a/include/trace/events/rpcgss.h > +++ b/include/trace/events/rpcgss.h > @@ -618,7 +618,7 @@ TRACE_EVENT(rpcgss_contex