From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Theodore Tso <tytso@mit.edu>
Cc: ksummit-discuss@lists.linuxfoundation.org
Subject: Re: [Ksummit-discuss] [MAINTAINERS SUMMIT] API replacement/deprecation
Date: Sat, 8 Sep 2018 10:15:01 +0200 [thread overview]
Message-ID: <CAMuHMdUkqSfhUqgzkxPwG6jAofLrsuwvTZdWk_trmP5_jrWDCA@mail.gmail.com> (raw)
In-Reply-To: <20180907205607.GZ5098@thunk.org>
Hi Ted,
On Fri, Sep 7, 2018 at 10:56 PM Theodore Y. Ts'o <tytso@mit.edu> wrote:
> On Fri, Sep 07, 2018 at 10:30:04PM +0200, Arnd Bergmann wrote:
> > I suspect that a lot of the cases that want NUL-padding also don't
> > want NUL-termination: when you store a string on disk in a fixed-length
> > record or transfer it over the network, you don't want to leak stack
> > data to the medium, but you also don't need the terminating character
> > because you know the maximum length already.
> >
> > strncpy() does exactly the right thing for that case, it's just that
> > this pattern is now a corner case, and gcc tends to flag such
> > usage with a warning about missing termination (unless you
> > use __nonstring) but doesn't flag the more common usage when
> > it looks correct.
>
> Yeah, the case I have is when I'm copying from a NUL-terminated string
> into a fixed char array. So if we had a function called
> "copy_string_to_char_array" (we'll figure out a better name later)
> which takes a source, destination, and size parameter, and which does
> the functional equivalent of:
>
> memset(dest, 0, size);
Why the memset()? strncpy() pads the destination with zeroes, so it
is not needed. This is basically the major reason to use strncpy().
> strncpy(src, dest, size);
Oh, you're copying in the wrong direction ;-)
> ... we could do something that's more efficient than the above, and
> does exactly what I'm looking for in this case.
>
> Of course, there could be other corner cases where strncpy() is
> justified; this is just the use case I care about. :-)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
next prev parent reply other threads:[~2018-09-08 8:15 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-05 22:57 Kees Cook
2018-09-05 23:41 ` Stephen Rothwell
2018-09-06 2:24 ` Steven Rostedt
2018-09-06 6:12 ` Julia Lawall
2018-09-06 18:24 ` Kees Cook
2018-09-06 23:18 ` Stephen Rothwell
2018-09-06 23:24 ` Kees Cook
2018-09-07 7:03 ` Takashi Iwai
2018-09-07 7:20 ` Johannes Berg
2018-09-07 7:31 ` Takashi Iwai
2018-09-07 9:42 ` Julia Lawall
2018-09-07 8:04 ` Jani Nikula
2018-09-07 9:38 ` Julia Lawall
2018-09-07 9:54 ` Jani Nikula
2018-09-07 10:05 ` Julia Lawall
2018-09-07 10:43 ` Jani Nikula
2018-09-07 10:25 ` Alexandre Belloni
2018-09-07 11:44 ` Mark Brown
2018-09-10 12:51 ` Mauro Carvalho Chehab
2018-09-11 8:10 ` Jani Nikula
2018-09-11 9:34 ` Mauro Carvalho Chehab
2018-09-11 11:08 ` Arnd Bergmann
2018-09-07 8:19 ` Jan Kara
2018-09-07 14:33 ` Theodore Y. Ts'o
2018-09-07 16:10 ` Kees Cook
2018-09-07 20:30 ` Arnd Bergmann
2018-09-07 20:56 ` Theodore Y. Ts'o
2018-09-08 8:15 ` Geert Uytterhoeven [this message]
2018-09-08 15:19 ` Theodore Y. Ts'o
2018-09-10 12:28 ` Mauro Carvalho Chehab
2018-09-10 16:09 ` Kees Cook
2018-09-07 10:14 ` Dan Carpenter
2018-09-07 10:40 ` Geert Uytterhoeven
2018-09-07 8:40 ` Maxime Ripard
2018-09-06 4:44 ` Julia Lawall
2018-09-06 10:04 ` Linus Walleij
2018-09-06 10:11 ` Geert Uytterhoeven
2018-09-06 14:59 ` Kees Cook
2018-09-06 15:06 ` Geert Uytterhoeven
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=CAMuHMdUkqSfhUqgzkxPwG6jAofLrsuwvTZdWk_trmP5_jrWDCA@mail.gmail.com \
--to=geert@linux-m68k.org \
--cc=ksummit-discuss@lists.linuxfoundation.org \
--cc=tytso@mit.edu \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox