This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: FAQ about strlcpy/strlcat ?
- From: Andreas Jaeger <aj at suse dot com>
- To: libc-alpha at sourceware dot org
- Date: Mon, 21 May 2012 11:12:47 +0200
- Subject: Re: FAQ about strlcpy/strlcat ?
- References: <201205210921.50117.aj@suse.com>
On Monday, May 21, 2012 09:21:50 Andreas Jaeger wrote:
> The FAQ contains a couple of not yet answered questions including one
> about strlcpy/strlcat.
>
> Could somebody write this one up, please?
>
> http://sourceware.org/glibc/wiki/FAQ
>
> Thanks,
> Andreas
Paul just added the following to the wiki:
The strlcpy and strlcat functions are sometimes promoted as a way of
copying strings more safely when retrofitting large bodies of existing code
without understanding the code in detail. The C11 standard's Annex K defines
optional functions strcpy_s and strcat_s that serve a similar need, albeit
less efficiently and with different calling conventions. Unfortunately, in
practice these functions can cause trouble, as their intended use
encourages silent data truncation, adds complexity and inefficiency, and does
not prevent all buffer overruns in the destinations. New standard library
functions should reflect good existing practice, and since it is not clear
that these functions are good practice they have been omitted from glibc.
The snprintf function can often be used as a portable substitute for these
functions. Also, compiling with gcc -D_FORTIFY_SOURCE can catch many of the
errors that these functions are supposed to catch, without having to modify
the source code.
Thanks,
Andreas
--
Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126