strncpy (was Re: samba 3.0.22 / 3.0.23)

Jeremy Allison jra at samba.org
Thu Jul 27 15:58:37 GMT 2006


On Thu, Jul 27, 2006 at 03:47:19PM +0000, David Collier-Brown wrote:
> Just fyi,
> 
> froggy> score -d strncpy -I. -I/usr/include/sys -Iinclude -Iubiqx -Itdb  
> -Ismbwrapper -I/opt/csw/include .
> Interface Badness  Calls
> --------- -------  -----
> sprintf      5     18
> strncat      5     12
> strncpy      5    131
> -------- -----    ---
>   Total    805
> 
> plus there are probably a few hidden in macros..
> 
> --dave
> 
> David Collier-Brown wrote:
> >  Oh dear, strncpy is
> >- often slower than strcpy, as it null-pads out to the specified length
> >- happily creates non-terminated strings unless you use
> >  length-1 and put in the terminating null manually.
> >
> >  Samba has an implementation of strlcpy, which does the "right thing",
> >and safe_strcat, which replaces strncat.  Alas, only the latter
> >is widely used.
> >
> >  I have a few minutes (;-)), so would you like a patch changing
> >all the strncats to strlcats with the proper lengths?  If so,
> >I can give you a diff -u, just tell me which source base to use.

strlcat in Samba is probably in a GPL licensed file. pam_winbind
and others must be BSD licensed for inclusing in proprietary
software. That's why strncat is being used here. To change it
you'll have to move a version of strlcat into the BSD licensed
files.

Jeremy.


More information about the samba-technical mailing list