🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #15940

Re: patch for nnrpd 1.5.1 to mmap .overview files

#15940
From: Jan-Pieter Cornet
Date: Mon, 17 Mar 1997 00:00
118 lines
4192 bytes
In article <5g61g0$hak$2@news.demos.su>,
Andrew A. Vasilyev  <andy@snm.demos.su> wrote:
>  getpagesize() works fine, but you've not answered the question: why is
>  it necessary to align maped region on page boundary?

I had some systems barf if I didn't align on a page boundary, I think it
was some Linux version, might be related to the libc version... and it
says in the manual page somewhere that it should be aligned on a pagesize,
so I decided to play it safe.

>  AND there is at least one more bug: if we have a single line in .overview
>  file, we get a second "bad format" error (after second memrchr() in
>  do {} while() loop). Probably the author correct this problem?

Thanks! Yes, that's another bug. Actually there were several bugs dwelling
in that part of the code, apparently I was a bit sleepy when I wrote that.
Another (incremental) patch included below. I've put the total patch on
my homepage, which contains the full patch against 1.5.1. See:
http://www.xs4all.nl/~johnpc/inn/

>  It's funny but I've also named the real mmap size as 'OVERmsize' :))

Heh :) Quite a coincidence, indeed.

[mailed and posted]

Best regards,

--
#! ##### Jan-Pieter Cornet ##### <johnpc@xs4all.net> ##### perl
++$_;$!=$_+++$_;($:,$,,$/,$*)=$!=~/.(.)...(.)(.).(.)/;$!=$_+$_;
($@,$\,$~)=$!=~/(.)(.).(.)/; $_="$,$/$:"; $@++; $~="$~$_";($_)=
\$$=~/\((.)/;$|=++$_;$_++;$|++;$~="$~ $@$:";`$~$/$\$*$, $|>&$_`


--- article.c	1997/03/11 16:42:28	1.32
+++ article.c	1997/03/17 09:47:31
@@ -1,4 +1,4 @@
-/*  $Revision: 1.32 $
+/*  $Revision: 1.37 $
 **
 **  Article-related routines.
 */
@@ -804,6 +804,8 @@
     struct stat 	sb;
     char*		p;
     static int		pagesize = 0;
+    int			hadlf;
+
 
     /* return true if already mapped */
     if ( OVERshm ) {
@@ -845,7 +847,7 @@
 	(void)close(OVERfd);
 	return FALSE;
     }
-    OVERmsize = (OVERsize + pagesize - 1) & ~pagesize;
+    OVERmsize = (OVERsize + pagesize - 1) & ~(pagesize - 1);
     if ( (OVERshm = mmap(NULL, OVERmsize, PROT_READ, MAP_SHARED, OVERfd, 0))
 	 == (caddr_t) -1 )
     {
@@ -864,7 +866,7 @@
     }
 
     /* get last entry */
-    if ( *(OVERshm + OVERsize - 1) != '\n' ) {
+    if ( !(hadlf = *(OVERshm + OVERsize - 1) == '\n') ) {
 	/*
 	 * If you get here, then your mmap() implementation sucks.
 	 * Go complain with your OS vendor, that their mmap() can't
@@ -877,13 +879,23 @@
 	YOUR_MMAP_SUCKS;
     }
     do {
-	p = memrchr(OVERshm + OVERsize - 1, '\n', OVERsize - 1);
+	p = memrchr(OVERshm + OVERsize - 2, '\n', OVERsize - 2);
 	if ( p == NULL ) {
-	    (void)munmap(OVERshm, OVERmsize);
-	    (void)close(OVERfd);
-	    OVERshm = NULL;
-	    return FALSE;
+	    if ( hadlf ) {
+		/* Apparently only 1 (usable) line */
+		OVERlast = OVERfirst;
+		OVERcache = NULL;
+		return TRUE;
+	    }
+	    else {
+		/* overview file only contains garbage. */
+		(void)munmap(OVERshm, OVERmsize);
+		(void)close(OVERfd);
+		OVERshm = NULL;
+		return FALSE;
+	    }
 	}
+	hadlf = TRUE;
 	OVERsize = p - OVERshm + 1;
 	if ( (p = memrchr((char*) OVERshm + OVERsize - 2, '\n',
 			    OVERsize - 1)) == NULL )
@@ -896,7 +908,14 @@
 	}
 	OVERlast = atol(p+1);
     }
-    while ( OVERlast == 0 && OVERsize-- );
+    while ( OVERlast == 0 && --OVERsize >= 2 );
+
+    if ( OVERsize < 2 ) {
+	(void)munmap(OVERshm, OVERmsize);
+	(void)close(OVERfd);
+	OVERshm = NULL;
+	return FALSE;
+    }
 
     OVERcache = NULL;
     return TRUE;

Technical Details
Message-ID: <5gj4cb$ppu$1@news0.xs4all.nl>
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: <331EE55D.1493@cwix.net> <5fv1s9$8ki$1@news.demos.su> <5g429n$d2s$1@news1.xs4all.nl> <5g61g0$hak$2@news.demos.su>

Show Full Headers
Complete Article Headers
Message-ID: <5gj4cb$ppu$1@news0.xs4all.nl>
Subject: Re: patch for nnrpd 1.5.1 to mmap .overview files
Date: Mon, 17 Mar 1997 00:00:00 +0000
From: johnpc@xs4all.nl (Jan-Pieter Cornet)
References: <331EE55D.1493@cwix.net> <5fv1s9$8ki$1@news.demos.su> <5g429n$d2s$1@news1.xs4all.nl> <5g61g0$hak$2@news.demos.su>
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: 226140072
Organization: XS4ALL
X-XS4ALL-Date: Mon, 17 Mar 1997 10:54:19 MET
Newsgroups: news.software.nntp