use of strncpy and strlen

Green, Paul Paul.Green at
Wed Jan 16 03:09:02 GMT 2002

Some C/Unix implementations now have a "strnlen" function, which is a safe
version of strlen. I'd be happy to contribute ours to Samba if you'd like
it. You could then deprecate strlen via the usual macro trick.

Paul Green, Senior Technical Consultant, Stratus Computer, Inc.
Voice: +1 978-461-7557; FAX: +1 978-461-3610; Video on request.

-----Original Message-----
From: jra at [mailto:jra at]
Sent: Tuesday, January 15, 2002 8:11 PM
To: Andrew Bartlett
Cc: Benjamin Kuit; samba-technical at; jra at
Subject: Re: use of strncpy and strlen

On Wed, Jan 16, 2002 at 12:00:04PM +1100, Andrew Bartlett wrote:
> Benjamin Kuit wrote:
> > 
> > Not sure if the respective developers are aware of the problem, but
> > there are some occurances whereby people use Strncpy (or strncpy) with
> > strlen like this:
> > 
> > Strncpy(dest, src, strlen(src));
> > 
> > Instead of using the size of the destination buffer for the length
> > parameter.
> > 
> > The developers might aswell #undef strcpy and use it instead.
> > 
> > Just my 1 cents worth. =)
> Yep, I fixed up a pile of these in passdb in HEAD, but they havn't made
> it to 2.2 yet.
> Can you give a list?  These need to be squahed...


	When you do this - just remove StrnCpy and move to strlcpy -
that way we can get rid of the annoying -1 also.


More information about the samba-technical mailing list