Subject: Re: server bind failure 48: Address already in use
To: None <email@example.com>
From: Ben Harris <firstname.lastname@example.org>
Date: 04/05/2003 20:13:33
In article <email@example.com> you write:
>--- Christian Biere <firstname.lastname@example.org> wrote:
>> Caffeinate The World <email@example.com> wrote:
>> > /* defensive programming */
>> > sprintf(txt,"Chat server bind failure %d: %s\n",errno,
>> > sys_errlist[errno]);
>> Some people will never understand...
>I'm a clueless new programmer. I would benefit much from your
>experience if you could tell me what mistake I made. "Some people will
>never understand" left me at square one, still clueless and staring at
You're using sprintf with %s, for a start, and passing a string whose length
you don't know (since sys_errlist is provided by the system), so that's a
buffer overrun waiting to happen. You then pass the buffer to a function
whose name suggests that it's printf-like, but you pass it as what is
presumably a format string, so any % characters in sys_errlist[errno] will
cause havoc. Of course, the best bit is that you then call this "defensive
At the very least, you should be using snprintf(), and probably strerror()
as well. If util_printf() really is printf-like, you should be using it
directly and not messing around with an intermediate buffer at all.
If you do this kind of thing with strings from the client, expect to find
yourself on BugTraq.
Come to think of it, consider writing in a language other than C. For all
its advantages, C's really not good at safe string handling.
Ben Harris <firstname.lastname@example.org>
Portmaster, NetBSD/acorn26 <URL:http://www.netbsd.org/Ports/acorn26/>