This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: FAQ about strlcpy/strlcat ?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]