🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #79574

Re: A pair of small patches I'd like to see in the mainstream.

#79574
From: Julien ÉLIE
Date: Sun, 26 Oct 2008 09:15
84 lines
5188 bytes
Hi D. Stussy,

> 1)  "strlcat"?  If by this you mean a strcat with a maximum length to copy
> specified, note that such is unnecessary as the routine has already checked
> to make certain sufficient space exists.  It cannot overrun the destination
> string length.

Yep, I have seen that the routine already checks the length.
I use strlcat everywhere because of INN's coding style:
    http://www.eyrie.org/~eagle/software/inn/docs/hacking.html#S9

%%
Use string handling functions that take counts for the size of the buffer
whenever possible.  This means using snprintf in preference to sprintf and
using strlcpy and strlcat in preference to strcpy and strcat.  Also, use strlcpy
and strlcat instead of strncpy and strncat, as it is much easier to audit uses
of the former than the latter.  strlcpy is like strncpy except that it always
nul-terminates and doesn't fill the rest of the buffer with nuls, making it
more efficient.  strlcat is like strncat except that it always nul-terminates
and it takes the total size of the buffer as its third argument rather than just
the amount of space left.  All of these functions are guaranteed to be available;
there are replacements in lib for systems that don't have them.

If you have to use a string copying routine that doesn't nul-terminate,
use memcpy instead.  Avoid introducing any uses of strcpy, strcat, strncpy,
or strncat so that we can use grep to find dangerous usages and switch them
to better functions.
%%


> 2)  Any issue with cp->Address fields should be handled by the called
> subroutine.  However, note that since this ADDS an address to a string that
> ALREADY HAS and address, the data design may already exclude local
> connections.

The string does not necessarily have an address:  if the connection is a local
one, there is no address (ip_address is empty and it should remain empty).
I agree it should be handled by the called subroutine.


> 3)  There should be a better way of checking of the address already appears
> in the list than strstr, but how often in the real world does one address in
> use be a non-identical substring of another in use at the same host?  I
> suppose that "10.x.y.24" and "10.x.y.247" could be in use, and if so, a
> ".24" found after the ".247" would be a substring and ignored.

We have to manually parse it, with a pointer to the following space in ip_address,
changing it to \0 and checking if the new address is the same as this one.
Then keep the place of this pointer, revert \0 to a space and go on the cycle
to the following space.
Unless you see something easier (especially without \0)?


> Although your suggested code for v2.5 below assumes one IPv4 and one IPv6,
> please also note that my design will handle multiple addresses of either
> family in any combination.

ip_addr is not a buffer of 64 characters (as in INN 2.4) but a buffer which can
contain up to the length of an IPv6 address.
In your design for INN 2.4, you cannot have 2 full IPv6 addresses (2×39 > 64).
Neither in mine.  But 2 IPv4 addresses work, as in yours.

Maybe the best solution would be to increase the size to something larger
(there is a const for 512 but it is perhaps too large...).


> I believe that your code may execute the strlcats even if they
> don't change the string while my code will skip them if there's insufficient
> room.

You're right.  I should add your checks before.


> Don't forget #ifdef's for IPv4 too (someone may compile an
> IPv6-only version someday).

With #ifdef for IPv4, the whole source code of INN  would have to been reviewed...

-- 
Julien ÉLIE

« -- Vous ne sortirez jamais d'ici étrangers ! Ce tombeau sera votre tombeau !
  -- Tout cela ne serait pas arrivé dans un menhir ! » (Astérix) 
Technical Details
Message-ID: <ge1cfd$cqc$1@news.trigofacile.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder1.news.weretis.net!newsfeeder.dynfx.net!weretis.net!news.trigofacile.com!not-for-mail
References: <gdb2rs$7av$1@snarked.org> <gdvpnh$qvj$1@news.trigofacile.com> <ge1138$79b$1@snarked.org>

Show Full Headers
Complete Article Headers
Message-ID: <ge1cfd$cqc$1@news.trigofacile.com>
Subject: Re: A pair of small patches I'd like to see in the mainstream.
Date: Sun, 26 Oct 2008 10:15:24 +0100
From: Julien ÉLIE <iulius@nom-de-mon-site.com.invalid>
References: <gdb2rs$7av$1@snarked.org> <gdvpnh$qvj$1@news.trigofacile.com> <ge1138$79b$1@snarked.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder1.news.weretis.net!newsfeeder.dynfx.net!weretis.net!news.trigofacile.com!not-for-mail
Newsgroups: news.software.nntp
Organization: TrigoFACILE -- http://www.trigofacile.com/
Lines: 84
NNTP-Posting-Host: aaubervilliers-151-1-40-153.w83-112.abo.wanadoo.fr
Mime-Version: 1.0
Content-Type: text/plain; format=flowed; charset="Windows-1252";
 reply-type=original
Content-Transfer-Encoding: 8bit
X-Trace: news.trigofacile.com 1225012526 13132 83.112.151.153 (26 Oct 2008
X-Complaints-To: abuse@trigofacile.com
NNTP-Posting-Date: Sun, 26 Oct 2008 09:15:26 +0000 (UTC)
In-Reply-To: <ge1138$79b$1@snarked.org>
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Windows Mail 6.0.6001.18000
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6001.18049