From eb9a5b0e859e5d396b7367df78c0ec97142446a2 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sat, 28 Sep 2013 01:04:40 +0000
Subject: [PATCH] Fix 2 bugs reported/root-caused by Deuce regarding
 corrupted/unpackable bundles: 1. If the unpackable bundle file was more then
 48 hours old, it would not try to rename it - the file date/time comparison
 logic was backwards and was trying to rename the file only if it was *less*
 than 48 hours old (and could in theory still be in transit). 2. If the
 unpackable bundle file was more than 48 hours old, SBBSecho would
 continuously and indefinitely try to unpack it consuming CPU cycles and
 generating log output. Forever.

---
 src/sbbs3/sbbsecho.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/sbbs3/sbbsecho.c b/src/sbbs3/sbbsecho.c
index 12751695c5..0aaba5eafb 100644
--- a/src/sbbs3/sbbsecho.c
+++ b/src/sbbs3/sbbsecho.c
@@ -1824,10 +1824,13 @@ BOOL unpack_bundle(void)
 		}
 		if(gi<g.gl_pathc) {
 			SAFECOPY(fname,g.gl_pathv[gi]);
+			gi++;
 			lprintf(LOG_DEBUG,"Unpacking bundle: %s",fname);
 			if(unpack(fname)) {	/* failure */
 				lprintf(LOG_ERR,"!Unpack failure");
-				if(fdate(fname)+(48L*60L*60L)>time(NULL)) {
+				if(fdate(fname)+(48L*60L*60L)<time(NULL)) {	
+					/* If bundle file older than 48 hours, give up and rename
+					   to "*.?_?" or (if it exists) "*.?-?" */
 					SAFECOPY(str,fname);
 					str[strlen(str)-2]='_';
 					if(fexistcase(str))
@@ -1837,15 +1840,13 @@ BOOL unpack_bundle(void)
 					if(rename(fname,str))
 						lprintf(LOG_ERR,"ERROR line %d renaming %s to %s"
 							,__LINE__,fname,str); 
-				} 
-			}
-			else {
-				lprintf(LOG_DEBUG,"Deleting bundle: %s", fname);
-				if(delfile(fname))	/* successful, so delete bundle */
-					lprintf(LOG_ERR,"ERROR line %d removing %s %s",__LINE__,fname
-						,strerror(errno));
+				}
+				continue;
 			}
-			gi++;
+			lprintf(LOG_DEBUG,"Deleting bundle: %s", fname);
+			if(delfile(fname))	/* successful, so delete bundle */
+				lprintf(LOG_ERR,"ERROR line %d removing %s %s",__LINE__,fname
+					,strerror(errno));
 			return(TRUE); 
 		} 
 	}
-- 
GitLab