🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: demon.ip.developers
Article #1150

Re: Bug in DOS/DIS Unbatch?

#1150
From: Peter Disdale
Date: Sun, 11 Feb 1996 00:00
44 lines
2390 bytes
In article <823977867snz@wash.demon.co.uk>
	   john@wash.demon.co.uk "John Washington" writes:

[ interesting comments on Snews 1.29 and 1.30 ]
> ......  Ahah!  The problem with a long path is that,
> even though fgets() chops it and doesn't overflow
> 'buf', there's a sprintf() call that tacks your own
> host and domain on the front of the path, BUT WRITES
> THAT LONGER STRING INTO ANOTHER BUFFER OF THE ONLY THE
> SAME SIZE!
>
> It would be more economical, as well as safer, if
> buf2 (.5K in 1.29, 1K in 1.30) were not allocated
> until it's needed, and then made the exact length
> required.

Agreed.  buf2 is declared on the stack anyway, and the overhead
of a malloc/free is minimal.  I have no doubt that overflowing
buf2 'as is' will produce interesting and unpredictable
results...   However,

> sprintf() is a brain damaged library function.  Any
> function that writes into an array should have a
> parameter that gives the no. of elements of the
> array.  Sadly we have to live with sprintf, since
> it's defined in ISO C, but all calls to it should
> always be carefully reviewed.

Oh but it does, John - it's just that most of us (myself included)
generally don't bother, and in most cases doesn't produce the
desired result anyway :(  It's so much easier to write:
   sprintf (buf, "%s", p);
than
   sprintf (buf, "%-511.511s", p);

which will _guarantee_ you don't overflow a 512 byte buffer, but
presents you with the problem of removing the trailing spaces
which you might not want...

sprintf is a *wonderful* function - I couldn't live without it!
Someone has to defend it against such vicious attacks as the
poor abused routine can't defend itself :-)
--
Pete
Technical Details
Message-ID: <824028106snz@pdlmail.demon.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <823946625snz@microvst.demon.co.uk> <823977867snz@wash.demon.co.uk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bb05,13da3e1a671290a7
X-Google-Attributes: gid10bb05,public
X-Google-Thread: fb525,13da3e1a671290a7
X-Google-Attributes: gidfb525,public
From: Peter Disdale <Pete@pdlmail.demon.co.uk>
Subject: Re: Bug in DOS/DIS Unbatch?
Date: 1996/02/11
Message-ID: <824028106snz@pdlmail.demon.co.uk>
X-Deja-AN: 139407104
x-nntp-posting-host: pdlmail.demon.co.uk
references: <823946625snz@microvst.demon.co.uk> <823977867snz@wash.demon.co.uk>
x-mail2news-path: pdlmail.demon.co.uk
organization: Papa Delta Limited
reply-to: pete@pdlmail.demon.co.uk
newsgroups: demon.ip.developers,demon.ip.support.pc