🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
2 messages
2 total messages Started by Francis C. Swasey Tue, 29 Jul 1997 00:00
More buffer overflows (1.6b2)
#19776
Author: 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-

Re: More buffer overflows (1.6b2)
#19816
Author: 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);

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads