Messages in this thread | ![/](/images/icornerl.gif) | | Date | Wed, 29 Apr 2015 10:24:37 +0200 | Subject | Re: revert "fs/befs/linuxvfs.c: replace strncpy by strlcpy" | From | Geert Uytterhoeven <> |
| |
On Wed, Apr 29, 2015 at 2:35 AM, Al Viro <viro@zeniv.linux.org.uk> wrote: > strncpy() has another use, though, and it can't be replaced by strlcpy() - > see the commits that had started this thread. IMO they (and anything > else of the same nature) really need to be reverted; using strlcpy() on > something that isn't guaranteed to be NUL-terminated is a serious bug.
To be honest, I never considered the "source is not NUL-terminated" case. Strings in C (if they are strings, and not "buffers"; with buffers you should know how many bytes are valid anyway) are always terminated ;-)
The other case we sometimes do want strncpy() for is the "crazy "fill with NUL" at the end" feature, to avoid leaking sensitive data. The alternative is to clear the target first, or the remainder afterwards.
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
| ![\](/images/icornerr.gif) |