Bugtraq mailing list archives
Re: Samba problems - errata
From: dleblanc () MINDSPRING COM (David LeBlanc)
Date: Sun, 10 May 1998 21:40:00 -0400
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
Current thread:
- Re: Serv-U FTP Exploit? Kevlar (Apr 30)
