From: Art Cancro Date: Wed, 12 Apr 2006 14:40:33 +0000 (+0000) Subject: serv_network.c: moved a call to CtdlFreeMessage() out one nesting X-Git-Tag: v7.86~4056 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=5f1e4b8298b4117224248fc480e733c52c36b3c7;p=citadel.git serv_network.c: moved a call to CtdlFreeMessage() out one nesting level to avoid prematurely freeing a message when spooling it to more than one node. --- diff --git a/citadel/citadel.h b/citadel/citadel.h index 313714150..2e1e812a2 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -33,7 +33,7 @@ extern "C" { /* * Text description of this software */ -#define CITADEL "Citadel 6.80" +#define CITADEL "Citadel 6.81" /* * REV_LEVEL is the current version number (multiplied by 100 to avoid having @@ -45,7 +45,7 @@ extern "C" { * usually more strict because you're not really supposed to dump/load and * upgrade at the same time. */ -#define REV_LEVEL 680 /* This version */ +#define REV_LEVEL 681 /* This version */ #define REV_MIN 591 /* Oldest compatible database */ #define EXPORT_REV_MIN 655 /* Oldest compatible export files */ diff --git a/citadel/citadel.nsi b/citadel/citadel.nsi index 32607b6c1..e646d7463 100644 --- a/citadel/citadel.nsi +++ b/citadel/citadel.nsi @@ -4,7 +4,7 @@ !include "${NSISDIR}\Contrib\Modern UI\System.nsh" !define MUI_PRODUCT "Citadel" -!define MUI_VERSION "6.80" +!define MUI_VERSION "6.81" !define MUI_WELCOMEPAGE !define MUI_LICENSEPAGE !define MUI_COMPONENTSPAGE @@ -18,7 +18,7 @@ ;!define MUI_ICON "${NSISDIR}\Contrib\Icons\modern-install.ico" ;!define MUI_UNICON "${NSISDIR}\Contrib\Icons\modern-uninstall.ico" -OutFile "citadel-6.80.exe" +OutFile "citadel-6.81.exe" BGGradient off LangString DESC_Citadel ${LANG_ENGLISH} "Citadel client and core libraries (required)" diff --git a/citadel/citadel.spec b/citadel/citadel.spec index 42b8a539f..3f9bd057e 100644 --- a/citadel/citadel.spec +++ b/citadel/citadel.spec @@ -1,7 +1,7 @@ # $Id$ Summary: Citadel, the flexible, powerful way to build online communities Name: citadel -Version: 6.80 +Version: 6.81 Release: 1 Copyright: GPL Group: Applications/Communications diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 73f38a931..eeb19d357 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -2047,21 +2047,31 @@ long send_message(struct CtdlMessage *msg) { void serialize_message(struct ser_ret *ret, /* return values */ struct CtdlMessage *msg) /* unserialized msg */ { - size_t wlen; + size_t wlen, fieldlen; int i; static char *forder = FORDER; - if (is_valid_message(msg) == 0) return; /* self check */ + /* + * Check for valid message format + */ + if (is_valid_message(msg) == 0) { + lprintf(CTDL_ERR, "serialize_message() aborting due to invalid message\n"); + ret->len = 0; + ret->ser = NULL; + return; + } ret->len = 3; for (i=0; i<26; ++i) if (msg->cm_fields[(int)forder[i]] != NULL) ret->len = ret->len + strlen(msg->cm_fields[(int)forder[i]]) + 2; - lprintf(CTDL_DEBUG, "serialize_message() calling malloc(%ld)\n", (long)ret->len); ret->ser = malloc(ret->len); if (ret->ser == NULL) { + lprintf(CTDL_ERR, "serialize_message() malloc(%ld) failed: %s\n", + (long)ret->len, strerror(errno)); ret->len = 0; + ret->ser = NULL; return; } @@ -2071,9 +2081,10 @@ void serialize_message(struct ser_ret *ret, /* return values */ wlen = 3; for (i=0; i<26; ++i) if (msg->cm_fields[(int)forder[i]] != NULL) { + fieldlen = strlen(msg->cm_fields[(int)forder[i]]); ret->ser[wlen++] = (char)forder[i]; - strcpy((char *)&ret->ser[wlen], msg->cm_fields[(int)forder[i]]); - wlen = wlen + strlen(msg->cm_fields[(int)forder[i]]) + 1; + safestrncpy((char *)&ret->ser[wlen], msg->cm_fields[(int)forder[i]], fieldlen+1); + wlen = wlen + fieldlen + 1; } if (ret->len != wlen) lprintf(CTDL_ERR, "ERROR: len=%ld wlen=%ld\n", (long)ret->len, (long)wlen); diff --git a/citadel/serv_network.c b/citadel/serv_network.c index b7a68ef9a..01220281a 100644 --- a/citadel/serv_network.c +++ b/citadel/serv_network.c @@ -785,8 +785,7 @@ void network_spool_msg(long msgnum, void *userdata) { * after sending out on the network */ if (msg->cm_fields['S'] != NULL) { - if (!strcasecmp(msg->cm_fields['S'], - "CANCEL")) { + if (!strcasecmp(msg->cm_fields['S'], "CANCEL")) { delete_after_send = 1; } } @@ -835,27 +834,30 @@ void network_spool_msg(long msgnum, void *userdata) { /* serialize it for transmission */ serialize_message(&sermsg, msg); - - /* write it to the spool file */ - snprintf(filename, sizeof filename,"%s/%s", - ctdl_netout_dir, - mptr->remote_nodename); - lprintf(CTDL_DEBUG, "Appending to %s\n", filename); - fp = fopen(filename, "ab"); - if (fp != NULL) { - fwrite(sermsg.ser, - sermsg.len, 1, fp); - fclose(fp); - } - else { - lprintf(CTDL_ERR, "%s: %s\n", filename, strerror(errno)); + if (sermsg.len > 0) { + + /* write it to the spool file */ + snprintf(filename, sizeof filename,"%s/%s", + ctdl_netout_dir, + mptr->remote_nodename); + lprintf(CTDL_DEBUG, "Appending to %s\n", filename); + fp = fopen(filename, "ab"); + if (fp != NULL) { + fwrite(sermsg.ser, + sermsg.len, 1, fp); + fclose(fp); + } + else { + lprintf(CTDL_ERR, "%s: %s\n", filename, strerror(errno)); + } + + /* free the serialized version */ + free(sermsg.ser); } - /* free the serialized version */ - free(sermsg.ser); } - CtdlFreeMessage(msg); } + CtdlFreeMessage(msg); } /* update lastsent */