From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Andrew Morton <akpm@linux-foundation.org>,
Arnd Bergmann <arnd@arndb.de>, Martin Wilck <mwilck@suse.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: [RFC][PATCH] lib/string: introduce sysfs_strncpy() and sysfs_strlcpy()
Date: Tue, 21 Aug 2018 15:57:34 +0200 [thread overview]
Message-ID: <20180821135734.GA19916@kroah.com> (raw)
In-Reply-To: <20180821095055.GA400@jagdpanzerIV>
On Tue, Aug 21, 2018 at 06:50:55PM +0900, Sergey Senozhatsky wrote:
> Hi Rasmus,
>
> On (08/21/18 09:59), Rasmus Villemoes wrote:
> > > +char *sysfs_strncpy(char *dest, const char *src, size_t count)
> > > +{
> > > + char *c;
> > > +
> > > + strncpy(dest, skip_spaces(src), count);
> >
> > I'd like to see where and how you'd use this, but I'm very skeptical of
> > count being used both for the size of the dest buffer as well as an
> > essentially random argument to strncpy - if count is also the maximum
> > number of bytes to read from the src, you'd need to take the
> > skip_spaces() into account, because there are not count bytes left after
> > that...
> > And if src is not necessarily nul-terminated, skip_spaces() by
> > itself is wrong.
>
> I think that sysfs input is always properly NULL-terminated. It may or
> may not contain \n, but \0 is expected to be there. Am I wrong?
sysfs data is always null terminated.
What exactly are you trying to do here? If a user sends you crappy data
in a sysfs file (like leading or trailing whitespace), well, you can
always just error out, no problem. You can be very strict in the
SINGLE_VALUE that you accept in your sysfs file. And yes, sysfs files
are single values, if you want to do more than that, you need to use
something else, so I really do not understand what problem you are
trying to solve here.
Please always post a user of your new api when you make stuff like this
otherwise we do not know how it is used, or even why you are adding it.
thanks,
greg k-h
next prev parent reply other threads:[~2018-08-21 13:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-21 6:24 [RFC][PATCH] lib/string: introduce sysfs_strncpy() and sysfs_strlcpy() Sergey Senozhatsky
2018-08-21 7:59 ` Rasmus Villemoes
2018-08-21 9:50 ` Sergey Senozhatsky
2018-08-21 9:54 ` Sergey Senozhatsky
2018-08-21 11:44 ` Sergey Senozhatsky
2018-08-21 12:00 ` Andy Shevchenko
2018-08-22 0:32 ` Sergey Senozhatsky
2018-08-21 12:43 ` Rasmus Villemoes
2018-08-22 5:13 ` Sergey Senozhatsky
2018-08-21 13:57 ` Greg Kroah-Hartman [this message]
2018-08-22 4:58 ` Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180821135734.GA19916@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mwilck@suse.com \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.