[6735] in bugtraq

home help back first fref pref prev next nref lref last post

Re: Samba problems - errata

daemon@ATHENA.MIT.EDU (David LeBlanc)
Mon May 11 18:21:29 1998

Date: 	Sun, 10 May 1998 21:40:00 -0400
Reply-To: David LeBlanc <dleblanc@MINDSPRING.COM>
From: David LeBlanc <dleblanc@MINDSPRING.COM>
To: BUGTRAQ@NETSPACE.ORG
In-Reply-To:  <3.0.3.32.19980510175456.00a9f280@mindspring.com>

I goofed somewhat - correction below:

At 05:54 PM 5/10/98 -0400, David LeBlanc wrote:

>At least snprintf returns an error if it can't fill fit everything -
>strncpy won't.  Probably the best case would be to have it look like so:

>if(snprintf(blah, blah...) < 0)
>{
>        wail;
>        complain;
>}

As has been pointed out to me by Theo, snprintf() isn't ANSI, and depends
on implementation.  The one I use on NT does return a negative number if
the buffer is completely filled.  Theo's (and presumably other UNIX's as
well, but then again it could be another sys V vs. BSD sort of thing - I
dunno - I'm an NT guy, so...) will return the number of bytes it _would_
have stuck in the buffer, which means you need to check the error a little
differently.  Same idea, and something to look out for whilst porting.

which would give you:

if(snprintf(buf, bufsize, args) + 1 > bufsize)
{
        wail;
        complain;
}

Still a safer way of dealing with things than strncpy.  BTW, I did check
and strncpy is ANSI - so it should behave the same.


David LeBlanc
dleblanc@mindspring.com

home help back first fref pref prev next nref lref last post