use of strncpy and strlen
Green, Paul
Paul.Green at stratus.com
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.
PG
--
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 samba.org [mailto:jra at samba.org]
Sent: Tuesday, January 15, 2002 8:11 PM
To: Andrew Bartlett
Cc: Benjamin Kuit; samba-technical at samba.org; jra at samba.org
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...
Andrew,
When you do this - just remove StrnCpy and move to strlcpy -
that way we can get rid of the annoying -1 also.
Jeremy.
More information about the samba-technical
mailing list