[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[leafnode-list] [PATCH] xoverutil recover fix for 1.9.3, 1.9.4 and 1.9.4-ma1



Hi, 

I recently found a small bug in leafnode-1.9.4 that makes leafnode's
fetchnews unable to recover from 0-byte files in news directories. 

Bug description:

getxover() tries to getxoverline(), which returns NULL if it cannot get
all necessary information from a news file, if it lacks headers or is a
0-byte file. I don't know how I happened to have these files, I don't
care.

Actually, getxover tries to recover by deleting the offending article,
and this (xoverutil.c:323) is where the bug bites us: it has improper
logic, the result of lstat() is checked with wrong logic, missing !.
Plus, error handling is wrong, so you additionally get the confusing
message that the file did not exist, while it actually exists (as
0-byte file). At that syslog "illegal article", the %m is pointless, it
can contain virtually any errno that is unrelated to the actual
problem, since we can open and read the 0-byte file, the errno is
unset. 

The attached patch fixes these bugs. It is applicable against
leafnode-1.9.3, leafnode-1.9.4 and leafnode-1.9.4-ma1.

-- 
Matthias Andree

 Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!



diff -ur xoverutil.c.orig xoverutil.c
--- xoverutil.c.orig	Wed Jul 21 16:48:29 1999
+++ xoverutil.c	Thu Jul 22 14:53:56 1999
@@ -316,15 +316,20 @@
 		    xoverinfo[art-xfirst].mallocd = 1;
 		} else {
 		    getcwd( s, 1024 );
-		    syslog( LOG_NOTICE, "illegal article: %s/%s: %m",
+		    syslog( LOG_NOTICE, "illegal article: %s/%s",
 			    s, de->d_name );
-		    if ( lstat( de->d_name, &st ) && S_ISREG( st.st_mode ) ) {
-			if ( unlink( de->d_name ) )
+		    if ( !lstat( de->d_name, &st )) {
+		      if (S_ISREG( st.st_mode ) ) {
+			if ( unlink( de->d_name ) ) {
 			    syslog( LOG_WARNING, "failed to remove %s/%s: %m",
 				    s, de->d_name );
-		    } else {
+			}
+		      } else {
 			syslog( LOG_WARNING, "%s/%s is not a regular file",
 				s, de->d_name );
+		      }
+		    } else {
+		      syslog( LOG_WARNING, "cannot lstat %s/%s: %m", s, de->d_name );
 		    }
 		}
 	    }