strncpy (was Re: samba 3.0.22 / 3.0.23)
davec-b at rogers.com
Thu Jul 27 16:15:26 GMT 2006
I think I have a copy of strlcpy I wrote before it was
commonly available... yes, but it returned source instead
of strlen(source). I'll fix that and submit it.
Which source tree (or trees) should I do diffs against?
Jeremy Allison wrote:
> On Thu, Jul 27, 2006 at 03:47:19PM +0000, David Collier-Brown wrote:
>>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..
>>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
David Collier-Brown, | Always do right. This will gratify
System Programmer and Author | some people and astonish the rest
davecb at spamcop.net | -- Mark Twain
More information about the samba-technical