[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new module 'strlcpy'
From: |
Bruno Haible |
Subject: |
Re: new module 'strlcpy' |
Date: |
Thu, 28 Sep 2017 19:54:37 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-93-generic; KDE/5.18.0; x86_64; ; ) |
Hi Jim,
> I developed a strong aversion to strncpy, and wrote this about it:
> https://meyering.net/crusade-to-eliminate-strncpy/
Thanks for your voice and past effort here.
Here's doc I propose to add to the gnulib documentation (and similar one
to wcscpy and wcsncpy):
diff --git a/doc/posix-functions/strcpy.texi b/doc/posix-functions/strcpy.texi
index 3289362..89c6cd3 100644
--- a/doc/posix-functions/strcpy.texi
+++ b/doc/posix-functions/strcpy.texi
@@ -17,3 +17,6 @@ OS X 10.8.
Portability problems not fixed by Gnulib:
@itemize
@end itemize
+
+Note: @code{strcpy (dst, src)} is only safe to use when you can guarantee that
+there are at least @code{strlen (src) + 1} bytes allocated at @code{dst}.
diff --git a/doc/posix-functions/strncpy.texi b/doc/posix-functions/strncpy.texi
index 3cc6b45..087acaf 100644
--- a/doc/posix-functions/strncpy.texi
+++ b/doc/posix-functions/strncpy.texi
@@ -17,3 +17,12 @@ OS X 10.8.
Portability problems not fixed by Gnulib:
@itemize
@end itemize
+
+Note: This function was designed for the use-case of filling a fixed-size
+record with a string, before writing it to a file. This function is
address@hidden appropriate for copying a string into a bounded memory area,
+because you have no guarantee that the result will be NUL-terminated.
+Even if you add the NUL byte at the end yourself, this function is
+inefficient (as it spends time clearing unused memory) and will allow
+silent truncation occur, which is not a good behavior for GNU programs.
+For more details, see @see{https://meyering.net/crusade-to-eliminate-strncpy/}.
- [PATCH 1/6] parse-datetime, posixtm: avoid uninit access, Paul Eggert, 2017/09/25
- [PATCH 2/6] parse-datetime: fix dependency, Paul Eggert, 2017/09/25
- [PATCH 3/6] sys_types: update URL, Paul Eggert, 2017/09/25
- [PATCH 4/6] maint: fix overflow checking in nap.h, Paul Eggert, 2017/09/25
- [PATCH 5/6] duplocale-tests: fix unlikely crash, Paul Eggert, 2017/09/25
- new module 'strlcpy', Bruno Haible, 2017/09/27
- Re: new module 'strlcpy', Paul Eggert, 2017/09/27
- Re: new module 'strlcpy', Bruno Haible, 2017/09/27
- Re: new module 'strlcpy', Bruno Haible, 2017/09/27
- Re: new module 'strlcpy', Jim Meyering, 2017/09/27
- Re: new module 'strlcpy',
Bruno Haible <=
- Re: new module 'strlcpy', Paul Eggert, 2017/09/28
- Re: new module 'strlcpy', Paul Eggert, 2017/09/27
- Re: new module 'strlcpy', Dmitry Selyutin, 2017/09/28
- Re: new module 'strlcpy', Tim Rühsen, 2017/09/28
- Re: new module 'strlcpy', Paul Eggert, 2017/09/28
- Re: alternatives to 'strlcpy', Bruno Haible, 2017/09/28
- Re: alternatives to 'strlcpy', Dmitry Selyutin, 2017/09/28
- Re: alternatives to 'strlcpy', Paul Eggert, 2017/09/28
- Re: alternatives to 'strlcpy', Paul Eggert, 2017/09/28
[PATCH 6/6] uniname/uniname-tests: integer overflow fix, Paul Eggert, 2017/09/25