🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #19816

Re: More buffer overflows (1.6b2)

#19816
From: Richard Michael Todd
Date: Tue, 29 Jul 1997 00:00
105 lines
4190 bytes
fswasey@btv.ibm.com (Francis C. Swasey) suggests this patch to innd/art.c:

> @@ -2684,9 +2684,9 @@
>  #endif	/* defined(DONT_HAVE_SYMLINK) */
>  	    }
>  	    *p++ = ' ';
> +	    Files.Data[Files.Size - 1] = '\0';
>              strncpy(p, linkname, (Files.Size - strlen(Files.Data) - 1)) ;
>  	    p += strlen(p);
> -	    Files.Data[Files.Size - 1] = '\0';
>  	}
>      }

This is not quite correct, I believe.  The argument (Files.Size -
strlen(Files.Data) -1) does not necessarily correspond to the amount
of room left in the buffer.  Consider the case where the buffer is
initially full of non-zero junk; strlen(Files.Data) will *always*
return Files.Size-1, making the strncpy always copy 0 bytes, even when
the buffer is nowhere near full.  I'd write the code segment in
question as follows:

#endif	/* defined(DONT_HAVE_SYMLINK) */
	    }
	    *p++ = ' ';
            strncpy(p, linkname, (Files.Data + Files.Size - p)) ;
	    p += strlen(p);
	    Files.Data[Files.Size - 1] = '\0';
	}


Bleurgh.  Looks like the site.c code you refer to in your patch has the
same problem, taking strlen()s of improperly terminated strings (both your
code and the original INN1.6b2 code). Note that the cc.c code is fine, as 
at each step the string in the buffer is built up using snprintf() or 
strncpy(), which will appropriately null-terminate things at each step; we
only get in trouble when we try to mix strncpy()s with the *p++ = ... 
construct.   Anyway, here's my version of the art.c and site.c 
patches.  My local copy of innd is somewhat hacked, so Your Line Numbers
Will Vary.

Index: art.c
===================================================================
RCS file: /ecn/src0/communications/INN-CVS-Repository/inn/innd/art.c,v
retrieving revision 1.24
diff -u -r1.24 art.c
--- art.c	1997/07/30 00:38:37	1.24
+++ art.c	1997/07/30 00:55:08
@@ -1624,8 +1624,8 @@
 	(void)snprintf(p, Xref.Size - Xref.Used,
 		" %s:%lu", ngp->Name, ngp->Filenum);
 	p += strlen(p);
+	Xref.Used = p - Xref.Data;
     }
-    Xref.Used = p - Xref.Data;
     Xref.Data[Xref.Used++] = '\n';
 }
 
@@ -2845,7 +2845,7 @@
 #endif	/* defined(DONT_HAVE_SYMLINK) */
 	    }
 	    *p++ = ' ';
-            strncpy(p, linkname, (Files.Size - strlen(Files.Data) - 1)) ;
+            strncpy(p, linkname, (Files.Data + Files.Size - p)) ;
 	    p += strlen(p);
 	    Files.Data[Files.Size - 1] = '\0';
 	}
Index: site.c
===================================================================
RCS file: /ecn/src0/communications/INN-CVS-Repository/inn/innd/site.c,v
retrieving revision 1.8
diff -u -r1.8 site.c
--- site.c	1997/07/24 02:27:01	1.8
+++ site.c	1997/07/30 01:23:04
@@ -1123,7 +1123,7 @@
 	if (fsp != sp && fsp->FNLwantsnames) {
 	    p = buff + strlen(buff);
 	    *p++ = ' ';
-	    (void)strncpy(p, sp->Name, sizeof(buff) - strlen(buff) - 2);
+	    (void)strncpy(p, sp->Name, buff + sizeof(buff) - p);
 	    buff[sizeof(buff) - 1] = '\0';
 	}
 	SITEwrite(fsp, buff);
@@ -1246,7 +1246,8 @@
 	}
 	break;
     }
-    *p++ = '\n';
+    if (p < (buff + sizeof(buff) - 1))
+	*p++ = '\n';
     if (Verbose) {
 	sep = "\t";
 	if (sp->Buffered && sp->Flushpoint) {
@@ -1269,7 +1270,8 @@
 	    sep = "; ";
 	}
 	if (sep[0] != '\t')
-	    *p++ = '\n';
+	    if (p < (buff + sizeof(buff) - 1))
+		*p++ = '\n';
 	if (sp->Spooling && sp->SpoolName) {
 	    (void)snprintf(p, sizeof(buff) - strlen(buff),
 		"\tSpooling to \"%s\"\n", sp->SpoolName);

Technical Details
Message-ID: <vz2k9i9iakt.fsf@wildstar.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <5rlima$120e$1@mdnews.btv.ibm.com>

Show Full Headers
Complete Article Headers
Message-ID: <vz2k9i9iakt.fsf@wildstar.net>
Subject: Re: More buffer overflows (1.6b2)
Date: Tue, 29 Jul 1997 00:00:00 +0000
From: Richard Michael Todd <rmtodd@wildstar.net>
References: <5rlima$120e$1@mdnews.btv.ibm.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.mbox.zip!not-for-mail
X-Deja-AN: 260375909
X-Complaints-To: news@choctaw.wildstar.net
X-Trace: choctaw.wildstar.net 870226675 16503 (None) 198.203.196.143
Organization: WildStar Internet Services
Newsgroups: news.software.nntp