|
Message-ID: <CAHp75VfO0SQ41zV1r3R2h2n2eRuGJzdsgHFzK7nRj85m7Xahgw@mail.gmail.com> Date: Thu, 21 Feb 2019 14:02:57 +0200 From: Andy Shevchenko <andy.shevchenko@...il.com> To: Kees Cook <keescook@...omium.org> Cc: "Tobin C. Harding" <tobin@...nel.org>, Shuah Khan <shuah@...nel.org>, Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Andy Shevchenko <andriy.shevchenko@...ux.intel.com>, Kernel Hardening <kernel-hardening@...ts.openwall.com>, LKML <linux-kernel@...r.kernel.org>, Matthew Wilcox <willy@...radead.org>, Rasmus Villemoes <linux@...musvillemoes.dk>, Daniel Micay <danielmicay@...il.com> Subject: Re: [PATCH 4/6] lib/string: Add string copy/zero function On Thu, Feb 21, 2019 at 2:49 AM Kees Cook <keescook@...omium.org> wrote: > On Mon, Feb 18, 2019 at 3:24 PM Tobin C. Harding <tobin@...nel.org> wrote: > > > > We have a function to copy strings safely and we have a function to copy > > strings _and_ zero the tail of the destination (if source string is > > shorter than destination buffer) but we do not have a function to do > > both at once. This means developers must write this themselves if they > > desire this functionality. This is a chore, and also leaves us open to > > off by one errors unnecessarily. > > > > Add a function that calls strscpy() then memset()s the tail to zero if > > the source string is shorter than the destination buffer. > > +/* Wrapper function, no arch specific code required */ > > +ssize_t strscpy_zeroed(char *dest, const char *src, size_t count); > > bikeshed: I think "pad" is shorter and more descriptive. How about > something like strspad() strscpy_pad() or strscpy_zero()? (just to > shorten it slightly) zero / zeroed examples in the kernel have semantics of getting some area completely zeroed. OTOH pad means different and we have examples as well (see seq_pad() as one). So, I would definitely vote for _pad b/c of semantics. -- With Best Regards, Andy Shevchenko
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.