From c997e60cc46af764600014690b26a04cf61fd84c Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 18 May 2022 20:52:09 +0100 Subject: [PATCH] Removed traces after realizing that I was hitting config.c_maxmsglen and not an actual bug. Added a debug message to indicate when this happened. --- citadel/modules/inboxrules/serv_inboxrules.c | 42 +++---- citadel/msgbase.c | 37 +++--- libcitadel/lib/stringbuf.c | 124 +++++++++---------- 3 files changed, 89 insertions(+), 114 deletions(-) diff --git a/citadel/modules/inboxrules/serv_inboxrules.c b/citadel/modules/inboxrules/serv_inboxrules.c index b7e01278f..a1a5f7c9b 100644 --- a/citadel/modules/inboxrules/serv_inboxrules.c +++ b/citadel/modules/inboxrules/serv_inboxrules.c @@ -1,16 +1,14 @@ -/* - * Inbox handling rules - * - * Copyright (c) 1987-2020 by the citadel.org team - * - * This program is open source software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ +// Inbox handling rules +// +// Copyright (c) 1987-2022 by the citadel.org team +// +// This program is open source software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. #include "sysdep.h" #include @@ -37,9 +35,7 @@ #include "ctdl_module.h" -/* - * The next sections are enums and keys that drive the serialize/deserialize functions for the inbox rules/state configuration. - */ +// The next sections are enums and keys that drive the serialize/deserialize functions for the inbox rules/state configuration. // Fields to be compared enum { @@ -170,7 +166,7 @@ struct inboxrules *deserialize_inbox_rules(char *serialized_rules) { return NULL; } - /* Make a copy of the supplied buffer because we're going to shit all over it with strtok_r() */ + // Make a copy of the supplied buffer because we're going to shit all over it with strtok_r() char *sr = strdup(serialized_rules); if (!sr) { return NULL; @@ -187,8 +183,8 @@ struct inboxrules *deserialize_inbox_rules(char *serialized_rules) { while ((token = strtok_r(rest, "\n", &rest))) { // For backwards compatibility, "# WEBCIT_RULE" is an alias for "rule". - // Prior to version 930, WebCit converted its rules to Sieve scripts, but saved the rules as comments for later re-editing. - // Now, the rules hidden in the comments become the real rules. + // Prior to version 930, WebCit converted its rules to Sieve scripts, but saved the rules as comments for + // later re-editing. Now, the rules hidden in the comments become the real rules. if (!strncasecmp(token, "# WEBCIT_RULE|", 14)) { strcpy(token, "rule|"); strcpy(&token[5], &token[14]); @@ -370,9 +366,7 @@ int inbox_do_redirect(struct irule *rule, long msgnum) { } -/* - * Perform the "reject" action (delete the message, and tell the sender we deleted it) - */ +// Perform the "reject" action (delete the message, and tell the sender we deleted it) void inbox_do_reject(struct irule *rule, struct CtdlMessage *msg) { syslog(LOG_DEBUG, "inbox_do_reject: sender: <%s>, reject", msg->cm_fields[erFc822Addr]); @@ -419,9 +413,7 @@ void inbox_do_reject(struct irule *rule, struct CtdlMessage *msg) { } -/* - * Perform the "vacation" action (send an automatic response) - */ +// Perform the "vacation" action (send an automatic response) void inbox_do_vacation(struct irule *rule, struct CtdlMessage *msg) { syslog(LOG_DEBUG, "inbox_do_vacation: sender: <%s>, vacation", msg->cm_fields[erFc822Addr]); diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 17e58e261..b33d904ab 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -2980,7 +2980,6 @@ StrBuf *CtdlReadMessageBodyBuf(char *terminator, // token signalling EOT int flushing = 0; int finished = 0; int dotdot = 0; - int lines_read = 0; // FIXME remove this after debugging LineBuf = NewStrBufPlain(NULL, SIZ); if (exist == NULL) { @@ -3000,7 +2999,6 @@ StrBuf *CtdlReadMessageBodyBuf(char *terminator, // token signalling EOT if (CtdlClientGetLine(LineBuf) < 0) { finished = 1; } - ++lines_read; if ((StrLength(LineBuf) == tlen) && (!strcmp(ChrPtr(LineBuf), terminator))) { finished = 1; } @@ -3020,33 +3018,28 @@ StrBuf *CtdlReadMessageBodyBuf(char *terminator, // token signalling EOT } /* if we've hit the max msg length, flush the rest */ - if (StrLength(Message) >= maxlen) flushing = 1; + if (StrLength(Message) >= maxlen) { + flushing = 1; + } } while (!finished); FreeStrBuf(&LineBuf); - // DEBUG remove this - int lines_in_buffer = num_tokens(ChrPtr(Message), '\n'); - syslog(LOG_DEBUG, "\033[31mLines from client : %d\033[0m", lines_read); - syslog(LOG_DEBUG, "\033[32mLines in buffer : %d\033[0m", lines_in_buffer); - assert(lines_read == lines_in_buffer); - + if (flushing) { + syslog(LOG_ERR, "msgbase: exceeded maximum message length of %d - message was truncated", maxlen); + } return Message; } -/* - * Back end function used by CtdlMakeMessage() and similar functions - */ -char *CtdlReadMessageBody(char *terminator, /* token signalling EOT */ +// Back end function used by CtdlMakeMessage() and similar functions +char *CtdlReadMessageBody(char *terminator, // token signalling EOT long tlen, - size_t maxlen, /* maximum message length */ - StrBuf *exist, /* if non-null, append to it; - exist is ALWAYS freed */ - int crlf /* CRLF newlines instead of LF */ - ) -{ + size_t maxlen, // maximum message length + StrBuf *exist, // if non-null, append to it; exist is ALWAYS freed + int crlf // CRLF newlines instead of LF +) { StrBuf *Message; Message = CtdlReadMessageBodyBuf(terminator, @@ -3055,10 +3048,12 @@ char *CtdlReadMessageBody(char *terminator, /* token signalling EOT */ exist, crlf ); - if (Message == NULL) + if (Message == NULL) { return NULL; - else + } + else { return SmashStrBuf(&Message); + } } diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 2605da7db..8830ffc60 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -1,20 +1,18 @@ -/* - * Copyright (c) 1987-2018 by the citadel.org team - * - * This program is open source software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ +// Copyright (c) 1987-2022 by the citadel.org team +// +// This program is open source software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define _GNU_SOURCE #include "sysdep.h" @@ -300,38 +298,37 @@ inline int StrLength(const StrBuf *Str) return (Str != NULL) ? Str->BufUsed : 0; } -/** - * @ingroup StrBuf_DeConstructors - * @brief local utility function to resize the buffer - * @param Buf the buffer whichs storage we should increase - * @param KeepOriginal should we copy the original buffer or just start over with a new one - * @param DestSize what should fit in after? - */ -static int IncreaseBuf(StrBuf *Buf, int KeepOriginal, int DestSize) -{ +// local utility function to resize the buffer +// Buf the buffer whichs storage we should increase +// KeepOriginal should we copy the original buffer or just start over with a new one +// DestSize what should fit in after? +static int IncreaseBuf(StrBuf *Buf, int KeepOriginal, int DestSize) { char *NewBuf; size_t NewSize = Buf->BufSize * 2; - if (Buf->ConstBuf) + if (Buf->ConstBuf) { return -1; + } - if (DestSize > 0) - while ((NewSize <= DestSize) && (NewSize != 0)) + if (DestSize > 0) { + while ((NewSize <= DestSize) && (NewSize != 0)) { NewSize *= 2; + } + } - if (NewSize == 0) + if (NewSize == 0) { return -1; + } - NewBuf= (char*) malloc(NewSize); - if (NewBuf == NULL) + NewBuf = (char*) malloc(NewSize); + if (NewBuf == NULL) { return -1; + } - if (KeepOriginal && (Buf->BufUsed > 0)) - { + if (KeepOriginal && (Buf->BufUsed > 0)) { memcpy(NewBuf, Buf->buf, Buf->BufUsed); } - else - { + else { NewBuf[0] = '\0'; Buf->BufUsed = 0; } @@ -344,18 +341,13 @@ static int IncreaseBuf(StrBuf *Buf, int KeepOriginal, int DestSize) return Buf->BufSize; } -/** - * @ingroup StrBuf_DeConstructors - * @brief shrink / increase an _EMPTY_ buffer to NewSize. Buffercontent is thoroughly ignored and flushed. - * @param Buf Buffer to shrink (has to be empty) - * @param ThreshHold if the buffer is bigger then this, its readjusted - * @param NewSize if we Shrink it, how big are we going to be afterwards? - */ -void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize) -{ - if ((Buf != NULL) && - (Buf->BufUsed == 0) && - (Buf->BufSize < ThreshHold)) { + +// shrink / increase an _EMPTY_ buffer to NewSize. Buffercontent is thoroughly ignored and flushed. +// Buf Buffer to shrink (has to be empty) +// ThreshHold if the buffer is bigger then this, its readjusted +// NewSize if we Shrink it, how big are we going to be afterwards? +void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize) { + if ((Buf != NULL) && (Buf->BufUsed == 0) && (Buf->BufSize < ThreshHold)) { free(Buf->buf); Buf->buf = (char*) malloc(NewSize); Buf->BufUsed = 0; @@ -363,6 +355,7 @@ void ReAdjustEmptyBuf(StrBuf *Buf, long ThreshHold, long NewSize) } } + /** * @ingroup StrBuf_DeConstructors * @brief shrink long term buffers to their real size so they don't waste memory @@ -864,42 +857,37 @@ void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset) return; if (Buf->BufSize - Offset < AppendBuf->BufUsed + Buf->BufUsed + 1) - IncreaseBuf(Buf, - (Buf->BufUsed > 0), - AppendBuf->BufUsed + Buf->BufUsed); + IncreaseBuf(Buf, (Buf->BufUsed > 0), AppendBuf->BufUsed + Buf->BufUsed); - memcpy(Buf->buf + Buf->BufUsed, - AppendBuf->buf + Offset, - AppendBuf->BufUsed - Offset); + memcpy(Buf->buf + Buf->BufUsed, AppendBuf->buf + Offset, AppendBuf->BufUsed - Offset); Buf->BufUsed += AppendBuf->BufUsed - Offset; Buf->buf[Buf->BufUsed] = '\0'; } -/** - * @ingroup StrBuf_Filler - * @brief Append a C-String to the buffer - * @param Buf Buffer to modify - * @param AppendBuf Buffer to copy at the end of our buffer - * @param AppendSize number of bytes to copy; set to -1 if we should count it in advance - * @param Offset Should we start copying from an offset? - */ -void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, unsigned long Offset) -{ +// Append a C-String to the buffer +// Buf Buffer to modify +// AppendBuf Buffer to copy at the end of our buffer +// AppendSize number of bytes to copy; set to -1 if we should count it in advance +// Offset Should we start copying from an offset? +void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, unsigned long Offset) { long aps; long BufSizeRequired; if ((AppendBuf == NULL) || (Buf == NULL)) return; - if (AppendSize < 0 ) + if (AppendSize < 0) { aps = strlen(AppendBuf + Offset); - else + } + else { aps = AppendSize - Offset; + } BufSizeRequired = Buf->BufUsed + aps + 1; - if (Buf->BufSize <= BufSizeRequired) + if (Buf->BufSize <= BufSizeRequired) { IncreaseBuf(Buf, (Buf->BufUsed > 0), BufSizeRequired); + } memcpy(Buf->buf + Buf->BufUsed, AppendBuf + Offset, @@ -908,7 +896,7 @@ void StrBufAppendBufPlain(StrBuf *Buf, const char *AppendBuf, long AppendSize, u Buf->buf[Buf->BufUsed] = '\0'; } -/** +/* * @ingroup StrBuf_Filler * @brief sprintf like function appending the formated string to the buffer * vsnprintf version to wrap into own calls -- 2.30.2