🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #19776

More buffer overflows (1.6b2)

#19776
From: Francis C. Swasey
Date: Tue, 29 Jul 1997 00:00
162 lines
6091 bytes
In tracking down the continuing sigsegv's on my server running 1.6b2,
I've uncovered what I percieve to be a few problems (not that these
are necessarily the cause of the problems I'm seeing).

1) innd/art.c around line 1552 has a call to snprintf that uses
"Xref.Size - Xref.Used" for the length and storing through pointer p.
p is then moved, but Xref.Used is NOT until the for loop drops
through.

2) innd/cc.c, innd/site.c have instances where it blindly stores a
character ('\n') into *p++ and then calls strlen(buff).  However, if
*p was the last character of buff, the return value of strlen is
guaranteed to be bad.

Here's today's patch:
---------------8<-------------------8<-------------------8<--------------
--- ./innd/art.c.orig3	Tue Jul 29 10:21:59 1997
+++ ./innd/art.c	Tue Jul 29 13:27:20 1997
@@ -1555,8 +1555,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';
 }
 
@@ -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';
 	}
     }
 
--- ./innd/cc.c.orig3	Tue Jul 29 13:40:44 1997
+++ ./innd/cc.c	Tue Jul 29 13:40:50 1997
@@ -817,25 +817,24 @@
 	p += strlen(strncpy(p, ModeReason, sizeof(buff) - strlen(buff) - 1));
 	break;
     }
-    *p++ = '\n';
     if (RejectReason) {
 	buff[sizeof(buff) - 1] = '\0';
-	p += strlen(strncpy(p, "Rejecting ", sizeof(buff) - strlen(buff) - 1));
+	p += strlen(strncpy(p, "\nRejecting ",sizeof(buff) - strlen(buff) - 1));
 	buff[sizeof(buff) - 1] = '\0';
 	p += strlen(strncpy(p, RejectReason, sizeof(buff) - strlen(buff) - 1));
     }
     else {
 	buff[sizeof(buff) - 1] = '\0';
-	p += strlen(strncpy(p, "Allowing remote connections",
+	p += strlen(strncpy(p, "\nAllowing remote connections",
 				sizeof(buff) - strlen(buff) - 1));
     }
 
     /* Server parameters. */
     for (i = 0, h = 0; CHANiter(&h, CTnntp) != NULL; )
 	i++;
-    *p++ = '\n';
+    buff[sizeof(buff) - 1] = '\0';
     (void)snprintf(p, sizeof(buff) - strlen(buff),
-	    "Parameters c %ld i %d (%d) l %ld o %d t %ld H %d T %d X %d %s %s",
+	    "\nParameters c %ld i %d (%d) l %ld o %d t %ld H %d T %d X %d %s %s",
 	    (long)Cutoff / (24L * 60L * 60L),
 	    MaxIncoming, i,
 	    LargestArticle, MaxOutgoing, (long)TimeOut.tv_sec,
@@ -845,21 +844,20 @@
     p += strlen(p);
 
     /* Reservation. */
-    *p++ = '\n';
     if (Reservation) {
+	buff[sizeof(buff) - 1] = '\0';
 	(void)snprintf(p, sizeof(buff) - strlen(buff),
-		"Reserved %s", Reservation);
+		"\nReserved %s", Reservation);
 	p += strlen(p);
     }
     else {
 	buff[sizeof(buff) - 1] = '\0';
-	p += strlen(strncpy(p, "Not reserved", sizeof(buff)-strlen(buff)-1));
+	p += strlen(strncpy(p, "\nNot reserved", sizeof(buff)-strlen(buff)-1));
     }
 
     /* Newsreaders. */
-    *p++ = '\n';
     buff[sizeof(buff) - 1] = '\0';
-    p += strlen(strncpy(p, "Readers ", sizeof(buff) - strlen(buff) - 1));
+    p += strlen(strncpy(p, "\nReaders ", sizeof(buff) - strlen(buff) - 1));
     if (NNRPFollows) {
 	buff[sizeof(buff) - 1] = '\0';
 	p += strlen(strncpy(p, "follow ", sizeof(buff) - strlen(buff) - 1));
@@ -877,9 +875,8 @@
     }
 
 #if defined(DO_TCL)
-    *p++ = '\n';
     buff[sizeof(buff) - 1] = '\0';
-    p += strlen(strncpy(p, "Tcl filtering ", sizeof(buff) - strlen(buff) - 1));
+    p += strlen(strncpy(p, "\nTcl filtering ",sizeof(buff) - strlen(buff) - 1));
     if (TCLFilterActive) {
 	buff[sizeof(buff) - 1] = '\0';
 	p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
@@ -889,9 +886,9 @@
     }
 #endif /* defined(DO_TCL) */
 #if defined(DO_PERL)
-    *p++ = '\n';
     buff[sizeof(buff) - 1] = '\0';
-    p += strlen(strncpy(p, "Perl filtering ", sizeof(buff) - strlen(buff) - 1));
+    p += strlen(strncpy(p, "\nPerl filtering ",
+		sizeof(buff) - strlen(buff) - 1));
     if (PerlFilterActive) {
 	buff[sizeof(buff) - 1] = '\0';
         p += strlen(strncpy(p, "enabled", sizeof(buff) - strlen(buff) - 1));
--- ./innd/site.c.orig3	Mon Jul 28 10:20:42 1997
+++ ./innd/site.c	Tue Jul 29 13:54:29 1997
@@ -1112,8 +1112,8 @@
 	if (fsp != sp && fsp->FNLwantsnames) {
 	    p = buff + strlen(buff);
 	    *p++ = ' ';
-	    (void)strncpy(p, sp->Name, sizeof(buff) - strlen(buff) - 2);
 	    buff[sizeof(buff) - 1] = '\0';
+	    (void)strncpy(p, sp->Name, sizeof(buff) - strlen(buff) - 2);
 	}
 	SITEwrite(fsp, buff);
     }
@@ -1235,7 +1235,8 @@
 	}
 	break;
     }
-    *p++ = '\n';
+    if (p < (buff + sizeof(buff) - 1))
+	*p++ = '\n';
     if (Verbose) {
 	sep = "\t";
 	if (sp->Buffered && sp->Flushpoint) {
@@ -1258,7 +1259,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);
---------------8<-------------------8<-------------------8<--------------

Frank
-- 
e-mail: fswasey@btv.ibm.com                                   ,,,
Tel: 802-769-4011 (tie: 446), Fax: 802-769-4253 (tie: 446)   (o o)
           Speaking *from* but not *for* IBM           -oOOO--(_)--OOOo-

Technical Details
Message-ID: <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

Show Full Headers
Complete Article Headers
Message-ID: <5rlima$120e$1@mdnews.btv.ibm.com>
Subject: More buffer overflows (1.6b2)
Date: Tue, 29 Jul 1997 00:00:00 +0000
From: fswasey@btv.ibm.com (Francis C. Swasey)
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: 260286733
Organization: IBM Microelectronics Division
Reply-To: fswasey@btv.ibm.com
Newsgroups: news.software.nntp