Skip to content
Snippets Groups Projects
Commit faadb5b9 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix 18 year old bug with updating/appending existing REP packets

18 years, 10 months ago I introduced a bug whereby .MSG files in outgoing REP packets were *always* truncated before newly-exported messages were added. Even though the log message would say "Updating /path/to/HUBID.REP" (rather than the usual "Creating ...") it was actually truncating the .MSG file, thus discarding any existing messages that were not previously successfully sent (!). I'm not sure what the problem was I was trying to solve at the time (some "Unix .rep creation bug") - but the change I made at the time was most definitely was not the correct fix. :-(

How I noticed this problem was the HEADERS.DAT Conference Number check I added to qwk_parse_header_list() back in August of 2019. I've been catching/logging those errors here on Vertrauen and collecting *.rep.bad files from occasional QWKnet node-submitted REP packets, but I didn't look into the cause until today: the HEADERS.DAT and VOTING.DAT files were being correctly appended even though the .MSG file was being truncated, so the files would be out-of-sync and this was the root-cause of the crossed-up message bodies/headers seen on DOVE-Net a year or more ago and apparently also the cause of occasionally lost messages from QWKnet (e.g. DOVE-Net) nodes.

To trigger this bug from the node side, you'd have to create a REP packet with one or more message in it and then fail to send it to your hub (e.g. VERT), for any reason. And then when you attempt another pack/call-out, the previously packed messages would be lost and the HEADERS.DAT file would contain stale/out-of-sync information. 

To simplify things, I'm now just using fopen(..., "ab") (append, binary) - fnopen() should not be needed when opening files in the temp_dir. In append mode, no subsequent fseek(..., SEEK_END) should be needed, so don't do that. And use fprintf() for its intended purpose.
parent 6e451021
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #1054 passed
/* Synchronet QWK reply (REP) packet creation routine */
/* $Id: pack_rep.cpp,v 1.51 2020/04/11 04:01:36 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -15,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -46,7 +32,7 @@ bool sbbs_t::pack_rep(uint hubnum)
char tmp[MAX_PATH+1],tmp2[MAX_PATH+1];
char hubid_upper[LEN_QWKID+1];
char hubid_lower[LEN_QWKID+1];
int file,mode;
int mode;
uint i,j,k;
long msgcnt,submsgs,packedmail,netfiles=0,deleted;
uint32_t u;
......@@ -82,17 +68,14 @@ bool sbbs_t::pack_rep(uint hubnum)
/*************************************************/
SAFEPRINTF2(str,"%s%s.MSG",cfg.temp_dir,hubid_upper);
fexistcase(str);
if((rep=fnopen(&file,str,O_CREAT|O_WRONLY|O_TRUNC))==NULL) {
errormsg(WHERE,ERR_CREATE,str,O_CREAT|O_WRONLY|O_TRUNC);
return(false);
if((rep=fopen(str, "ab"))==NULL) {
errormsg(WHERE, ERR_CREATE, str, 0);
return false;
}
if(filelength(file)<1) { /* New REP packet */
SAFEPRINTF2(str,"%-*s"
,QWK_BLOCK_LEN,hubid_upper); /* So write header */
fwrite(str,QWK_BLOCK_LEN,1,rep);
if(ftell(rep) < 1) { /* New REP packet */
fprintf(rep, "%-*s"
,QWK_BLOCK_LEN, hubid_upper); /* So write header */
}
fseek(rep,0L,SEEK_END);
if(!(cfg.qhub[hubnum]->misc&QHUB_NOHEADERS)) {
SAFEPRINTF(str,"%sHEADERS.DAT",cfg.temp_dir);
fexistcase(str);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment